Re: EuSQL
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 07, 2005
- 579 views
Alex Chamberlain wrote: > > Alex Chamberlain wrote: > > I found the Solution: > > > > SELECT CATEGORIES.ID, CATEGORIES.NAME, CATEGORIES.DEFAULT_PRICE, > > COUNT(PRODUCTS.CAT_ID) > > FROM CATEGORIES INNER JOIN PRODUCTS ON CATEGORIES.ID = PRODUCTS.CAT_ID GROUP > > BY CATEGORIES.ID, CATEGORIES.NAME, CATEGORIES.DEFAULT_PRICE; > > > > Actually, it only shows the categories that actually have a product in. > Problem!?! This is what outer (a LEFT JOIN, in this case) joins are for: SELECT CATEGORIES.ID, CATEGORIES.NAME, CATEGORIES.DEFAULT_PRICE, COUNT(PRODUCTS.CAT_ID) FROM CATEGORIES LEFT JOIN PRODUCTS ON CATEGORIES.ID = PRODUCTS.CAT_ID GROUP BY CATEGORIES.ID, CATEGORIES.NAME, CATEGORIES.DEFAULT_PRICE; Matt Lewis