私はテーブルcategories
とテーブルを持っていますposts
。投稿が3つ以上あるカテゴリを返したい。
私の質問
SELECT `categories`.`category_title`, COUNT(posts.post_id) as total_posts
FROM (`categories`)
JOIN `posts` ON `posts`.`category_id` = `categories`.`category_id`
HAVING `total_posts` > 3
ORDER BY `categories`.`date_created` desc
1行だけを返します。2つのクエリを使用せずにこのタイプのクエリを実行する正しい方法は何ですか?