[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Conditional Query in Oracle

Posted on 2014-08-16
2
Medium Priority
?
176 Views
Last Modified: 2014-08-22
Greeting,

I need suggestion on a conditional query in Oracle like the followings.
say I have a table TBL1 with field1,field2 and field3.
I want to have select statement like the following


if TBL1.field1= 'X' then TBL1 left join TBL2
if TBL1.field1= 'Y' then TBL1 left join TBL3
if TBL1.field1= 'Z' then TBL1 left join TBL4


thanks.
0
Comment
Question by:mrong
2 Comments
 
LVL 36

Accepted Solution

by:
ste5an earned 2000 total points
ID: 40265249
E.g.  
SELECT	T1.*,
	T2.*,
	T3.*,
	T4.*
FROM	TBL1 T1
	LEFT JOIN TBL2 T2 ON <JoinCondition> AND T1.field1 = 'X'
	LEFT JOIN TBL3 T3 ON <JoinCondition> AND T1.field1 = 'Y'
	LEFT JOIN TBL4 T4 ON <JoinCondition> AND T1.field1 = 'Z';

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 40267643
Is field1 in tbl1 always going to contain only 'X' or "Y" or 'Z"?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question