I want to use a where statement on a value from a joined table. Can’t figure it out:
SELECT item.*, count(articles.authorid) AS articlecount
FROM #_authors AS item
LEFT JOIN #_articles AS articles ON (articles.authorid = item.id)
WHERE item.published=1
AND articlecount>3
ORDER BY articlecount DESC
The orderby works fine, but when I add “AND articlecount>3” I get the error: “#1054 – Unknown column ‘articlecount’ in ‘where clause'”.
What is the best way to include the WHERE on articlecount? Thanks in advance!
For aggregate columns, you use
HAVING, like this: