Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Need help joining tables


Gian04 - 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


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4331144.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com