Mysql inner join twice and use WHERE on both joins -
in mysql, want select a.* a
inner join condition satisfied whether directly (joining table b
) or through join table (c
), where b.field = myvalue
. can point out proper way results?
i have following tables: a, b, c, associated follows (a joins b, b joins c, joins c):
b / \ --- c
it looks pretty straightforward, empty set when run following code, though results when restrict search joining b through c:
select a.* inner join c on c.id = a.c_id inner join b b_thru_c on b_thru_c.id = c.b_id inner join b b_from_a on b_from_a.id = a.b_id b_thru_c.field = 'myvalue' or b_from_a.field = 'myvalue'; # yields empty set select a.* inner join c on c.id = a.c_id inner join b b_thru_c on b_thru_c.id = c.b_id b_thru_c.field = 'myvalue'; # yields results
how this?
select a.* left outer join c on c.id = a.c_id inner join b on b.id = a.b_id or b.id = c.b_id b.field = 'myvalue';
Comments
Post a Comment