Saturday, June 5, 2010

Mysql query return the count from multiple table with left join

This the MySQL query with table where home table has one to many relation with many table,
 Here is code that return the count from multiple table.


  select  h.id,h.home_name,count(n.home_id) as ncount,
count(e.home_id) as ecount,count(b.home_id) as bcount,
count(s.home_id) as scount
 from home as h left join news as n on (h.id=n.home_club_id)
left join events as e on (h.id=e.home_id)
left join billboard as b on (h.id=b.home_id)
left join store as s on(h.id=s.home_id) where 1

Have Dream Day

No comments:

Post a Comment