Issue with mysql multiple left join and group by -
well got 3 tables:
tb1:
tb1_id pk tb1_name tb2:
tb2_id pk tb1_id fk tb3:
tb3_id pk tb2_id fk and got query:
select a.tb1_nome ,b.tb2_id ,count(c.tb2_id) lins tb1 left join tb2 b on a.tb1_id=b.tb1_id left join tb3 c on b.tb2_id=c.tb2_id group b.tb2_id order a.tb1_id desc but doesn't returns rows of tb1.
i got 3 tables need get rows of tb2 matches tb1 , show count of rows of tb3 matches tb2
i think need use inner join instead of left join. inner join selects rows has records on table joined. give try , have feed later :)
select a.tb1_name, b.tb2_id, count(c.tb2_id) totalcount tb1 inner join tb2 b on a.tb1_id = b.tb1_id inner join tb3 c on b.tb2_id = c.tb2_id group a.tb1_name, b.tb2_id order a.tb2_id desc
Comments
Post a Comment