Select records that match a field, but order them by a different field
my tables look like this:
tags: id, name, description
tag_relations: tag, item
item references the id of another table and tag references the id of the
tags table.
So I'm trying to select the most used tags:
SELECT t.*, COUNT(r.item) AS item_count
FROM tag_relations as r
INNER JOIN tags as t ON r.tag = t.id
GROUP BY t.id
ORDER BY item_count
which works, but if I add
WHERE t.id = ?
the item_count is always 1...
Is there any way I could still have the global tag count with a select
statement that selects only 1 tag or a specific set of tags?
No comments:
Post a Comment