Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Need help joining tables

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

Preferred Member

10+ Year Member

joined:Nov 25, 2005
votes: 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'

Please Help
4:18 pm on June 27, 2011 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
votes: 76

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members