SQL Question – Conditional Join on Columns based on value of one column

Here is my answer.

Try a union
select * from tbla ta, tblb tb
where ta.column_1 = 1
and ta.column_2 = tb.column_2
union
select * from tbla ta, tblb tb
where ta.column_1 = 2
and ta.column_2 = tb.column_2
and ta.column_3 = tb.column_3
union
select * from tbla ta, tblb tb
where ta.column_1 = 3
and ta.column_2 = tb.column_2
and ta.column_3 = tb.column_3
and ta.column_4 = tb.column_4
the end

Here is the website to see other answers

http://stackoverflow.com/questions/10846936/sybase-conditional-join-on-columns-based-on-value-of-one-column/10866671#10866671