I need to know if an IF can be inserted into a SQL query.
If the value of a column is X make a JOIN with a table but if it is Y make a JOIN with another table.
It's like: Select * from Table1 If (Table1.value = 1) then JOIN Table2 else JOIN Table3
can this be done?
You would use left join. Something like this:
left join
select . . . from t1 left join t2 on t1.column = 'X' and <other conditions> left join t3 on t1.column = 'Y' and <other conditions> where t1.column in ('X', 'Y')
1.4m articles
1.4m replys
5 comments
57.0k users