
February 6th, 2013, 03:51 AM
|
|
Contributing User
|
|
Join Date: Jul 2005
Posts: 119

Time spent in forums: 1 Day 5 h 57 m 14 sec
Reputation Power: 8
|
|
|
JOIN count wont show items with 0 results
Hey all,
I've been playing around with this query to get a count of then number of times a particular tag occurs in a relational table.
I have 2 tables
TAGS
id, tag
1, tag1
2, tag2
3, tag3
4, tag4
COMMENT_TAGS
comment_id, tag_id
1, 1
2, 1
3, 2
Here is the I've come up with
SELECT * FROM (SELECT T.tag, COUNT(C.tag_id) AS num FROM tags T JOIN comment_tags C ON T.id = C.tag_id GROUP BY T.tag) AS A WHERE A.tag LIKE '%tag%' LIMIT 10
I get the following
tag, num
tag1, 2
tag2, 1
What I'm trying to get it
tag, num
tag1, 2
tag2, 1
tag3, 0
tag4, 0
Am I trying to do this the wrong way?
Any help would be appreciated.
|