| Welcome to WebmasterWorld Guest from 220.127.116.11 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Need help joining tables|
| 5:31 am on Jun 26, 2011 (gmt 0)|
I have to join tables based on conditions
table : main
table : a
table : b
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'
| 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.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved