Reputation: 1
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?
Upvotes: 0
Views: 61
Reputation: 1269933
You would use left join
. Something like this:
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')
Upvotes: 0