sql - How to join according to value of a field on mysql -
i have user table in database , there user_type field, has 0 or 1. if value 0, want joined teacher table if not student table.
is possible?
you use cross apply or cte dont specify db using should work generic solution
select t1.fields,t2.fields user_table t1 left join teacher_table t2 on t1.id=t2.id , t1.user_type_field=0 union select t1.fields,t2.fields user_table t1 left join student_table t2 on t1.id=t2.id , t1.user_type_field=1
Comments
Post a Comment