Using CASE Statements in LEFT OUTER JOIN in SQL
Posted
by s khan
on Stack Overflow
See other posts from Stack Overflow
or by s khan
Published on 2010-03-22T05:41:15Z
Indexed on
2010/03/22
6:01 UTC
Read the original article
Hit count: 276
I've got a scenario where I want to switch on two different tables in an outer join. It goes something like this:-
select mytable.id,
yourtable.id
from mytable
left outer join (case
when mytable.id = 2 then table2
yourtable on table1.id = table2.id
else
table3 yourtable on table1.id = table3.id
end)
...but it doesn't work. Any suggestions?
© Stack Overflow or respective owner