help with sql statement

If I have a table full of items, and each item has a category, what would be the sql statement that I can use to return html like this:

category one (5 items)
category two (34 items)
category three (17 items)
category four (2 items)
category five (11 items)

As I don't know what your tables look like in detail I would guess something like this should do the trick:
SELECT category_name, category_id, COUNT(*) AS item_count FROM category left join item on category.category_id = item.item_category_id GROUP BY category_name, category_id ORDER BY category_name ASC;

thx! it worked perfectly

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.