Re: EuSQL

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu