How to display how many times each records in a table used by other table

Posted by Fredy on Stack Overflow See other posts from Stack Overflow or by Fredy
Published on 2012-07-09T08:58:57Z Indexed on 2012/07/09 9:15 UTC
Read the original article Hit count: 197

Filed under:

I have a problem with my query, below are two tables that tbl_tag and tbl_tag_usedby. I want to show how much of each record in tbl_tag used by record in tbl_tag_usedby.

enter image description here

Here is a query that I use:

SELECT t.*, COUNT(u.tagid) AS totale FROM tbl_tag t LEFT JOIN tbl_tag_usedby u ON u.tagid = t.id AND t.status =1 GROUP BY u.tagid

and the results are as below:

enter image description here

In this case the record id from 2 to 6 do not appear in the query results, I want record id from 2 to 6 are also shown and on the field "totale" its value is 0.

Can anyone help me?

© Stack Overflow or respective owner

Related posts about mysql