Bonjour,
J'ai une table article_category et une table article, un article étant rattaché à une catégorie. Je voudrais obtenir la liste des catégories avec le nombre d'articles actifs (0 si la catégorie ne contient aucun article actif). La requête suivante ne me renvoit que les catégories ayant des articles actifs.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 SELECT category.category_id, category.name AS category_name, category.description, count( article.article_id ) AS number FROM article_category AS category LEFT OUTER JOIN article ON article.category_id = category.category_id WHERE article.is_published =1 AND article.publication_date <= str_to_date( '2008-04-13 23:14:03', '%Y-%m-%d %H:%i:%s' ) AND ( article.expiration_date IS NULL OR article.expiration_date >= str_to_date( '2008-04-13 23:14:03', '%Y-%m-%d %H:%i:%s' ) ) GROUP BY category.category_id, category.name, category.description ORDER BY category.name LIMIT 0 , 30
Partager