Group By query with count problem
Hi,
Having trouble getting the results I need with this query.
Basically have two tables, content and contentheaders.
The contentheaders table lists the headings for various menu items, such as White Wine, Red Wine, Champagne etc.
The content table contains the actual menu items that fall under the various headings, such as chardonnay, pinot blanc, riesling under the White Wine heading, and so on.
I am trying to use a select query to display all the headings for the wine webpage, with a count of the number of menu items in the content table for each heading.
The query I have is:
SELECT contentheaders.headername, contentheaders.headerID,
COUNT(content.contentID) As total From contentheaders, content Where contentheaders.contentarea = '$strID' And contentheaders.headerID = content.header Group By contentheaders.headername, contentheaders.headerID
At the moment the query doesn't display any results at all, since there aren't any menu items for those headings yet, but I would still like the query to display the heading names, with a count of zero next to each one, and of course with an accurate count once the content table is populated.
This is the end result I am looking for:
Header Names Number of items
White wine 0
Red Wine 0
Champagne 0
Instead it is returning nothing.
Any help would be greatly appreciated.
Thanks,
Paul
|