Re: EuSQL
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 07, 2005
- 570 views
cklester wrote: > > Alex Chamberlain wrote: > > > > I have 2 tables - CATEGORIES & PRODUCTS. Each product belongs to a Category > > and the category's ID is stored in Products as CAT_ID. How do I select the > > ID from > > Category and count how many Products contain that ID as a CAT_ID? <snip> > Or you could do it with a join (this isn't tested but gives the idea): > > SELECT COUNT(PRODUCTS.UNIQUE_ID) FROM CATEGORIES INNER JOIN PRODUCTS WHERE > CAT_NAME='Food' > Or, to get a list of all categories: SELECT CATEGORIES.ID, COUNT(PRODUCTS.ID) FROM CATEGORIES INNER JOIN PRODUCTS ON CATEGORIES.ID = PRODUCTS.CAT_ID GROUP BY CATEGORIES.ID Matt Lewis