How to display a list of categories, indicating for each category the number of goods?

Category table:

idcategory int(11); title varchar(255); slug varchar(255); 

Product table:

 idproduct(int11); title varchar(255); description text; category_id int(11); price decimal(19,2); 
  • , And the approximate kind of tables is known though? Well on vskidku: select category_name from table group by category_name - nobody
  • group them by categories, if roughly: select group_name, count(1) as cnt from table_name group by group_name - BOPOH

1 answer 1

 SELECT category_id as category, count(*) AS cnt FROM таблица_продуктов GROUP BY category_id 

You can even zodzhoynit category table to get a description of the categories from it.