ciber Posted June 23, 2010 Share Posted June 23, 2010 I am performing a query in my database to fetch information, and count how many of a specific type of articles there are. My database stores 3 types of articles, a review, preview and article - however, if one of them counts a zero value, it does not show the entry. ie: if I have 3 reviews, 4 previews and 1 article it will show. But it I have 3 reviews, 0 previews and 1 article it wont show (or what ever combination of items = zero) how can I fix this? here is my code: COUNT(articles_1.type) AS reviews, COUNT(articles.type) AS previews, COUNT(articles_2.type) AS articles this extract counts the types of articles such as review, preview or just a normal article SELECT product.screenshots, product.renders, product.moreimages, product.ytplaylist, product.minreq, product.download, COUNT(articles_1.type) AS reviews, COUNT(articles.type) AS previews, COUNT(articles_2.type) AS articles, product.title FROM inf81_product.product INNER JOIN inf81_product.categories ON categories.id = product.cat INNER JOIN inf81_product.articles ON articles.game = product.id INNER JOIN inf81_product.articles articles_2 ON articles_2.game = product.id INNER JOIN inf81_product.articles articles_1 ON articles_1.id = product.id WHERE categories.slug = '$var1' AND product.slug = '$var2' AND articles.type = 'review' AND articles_1.type = 'preview' AND articles_2.type = 'article' GROUP BY product.id LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/205627-query-results-empty-if-count-0/ Share on other sites More sharing options...
ciber Posted June 23, 2010 Author Share Posted June 23, 2010 Got it to work, made use of subqueries Quote Link to comment https://forums.phpfreaks.com/topic/205627-query-results-empty-if-count-0/#findComment-1076164 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.