Conditional Query in Oracle

mrong
mrong used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Developer
Commented:
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

awking00Information Technology Specialist

Commented:
Is field1 in tbl1 always going to contain only 'X' or "Y" or 'Z"?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial