homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Need help joining tables
Gian04




msg:4331146
 5:31 am on Jun 26, 2011 (gmt 0)

I have to join tables based on conditions

table : main
condition_field
unique_id
username

table : a
unique_id
companyname

table : b
username
companyname

If main.condition_field = "X"
I need to Left Join table a on main.unique_id = a.unique_id


Else if main.condition_field = "Y"
I need to Left Join table b on main.username = b.username

So far I only have this query joining 2 table main and table a

SELECT main.*, a.* FROM main LEFT JOIN a ON main.unique_id = a.unique_id where main.unique_id='X'

Please Help

 

LifeinAsia




msg:4331643
 4:18 pm on Jun 27, 2011 (gmt 0)

Probably easier to use an IF statement or CASE function- actual implementation depends on your specific DB.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved