Query help: Get category and number of items in one query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mfyahya@gmail.com

    Query help: Get category and number of items in one query

    Hi,
    I have a `category` table with columns cat_id and cat_name. And another
    `items` table with columns item_id, item_name and cat_id.
    I want a query which will select display each category name and the
    number of items in that category. I could do this in two sql
    statements, is it possible to do it in one?

    Thanks~

  • Bill Karwin

    #2
    Re: Query help: Get category and number of items in one query

    mfyahya@gmail.c om wrote:[color=blue]
    > Hi,
    > I have a `category` table with columns cat_id and cat_name. And another
    > `items` table with columns item_id, item_name and cat_id.
    > I want a query which will select display each category name and the
    > number of items in that category. I could do this in two sql
    > statements, is it possible to do it in one?[/color]

    Look up GROUP_CONCAT in the MySQL reference documentation.

    Also see this thread on this newsgroup from a couple of weeks back:


    Regards,
    Bill K.

    Comment

    Working...