join 2 tables on differnt joins based on 2 different conditions

when you join 2 tables on differnt joins based on 2 different values, is it possible to consolidate the 2 queries into 1?

select * from a join b on a.id = b.id1 and b.indicator = 0
union
select * from a join b on a.id = b.id2 and b.indicator = 1
LVL 5
25112Asked:
Who is Participating?
 
twolConnect With a Mentor Commented:
select * from a inner join b
on (a.id = b.id1 and b.indicator = 0) or (a.id = b.id2 and b.indicator = 1 )
0
 
deightonConnect With a Mentor Commented:
I believe the SQL you gave does exactly what you ask, so the answer is yes
0
 
25112Author Commented:
works..
0
All Courses

From novice to tech pro — start learning today.