Listing all categories with total number of products

Asked

Viewed 39 times

0

I need to mount a query that displays the name of all categories, and in front of each name the total number of products.

The tables are:

 Categorias (cat_codigo, cat_nome)
 Produtos (pro_codigo, pro_codigo_categoria pro_nome)      

 Exemplo:

 Parafusos (58)
 Brocas (42)
 Chaves (33)

I know how to make the connections between the two tables, but I’m in doubt about getting the full amount:

 select * from categorias CAT LEFT JOIN produtos PRO ON CAT.cat_codigo=PRO.pro_codigo_categoria

1 answer

1


 select  count(PRO.pro_nome), CAT.cat_nome
 from categorias CAT
 INNER JOIN 
   produtos PRO ON CAT.cat_codigo=PRO.pro_codigo_categoria
 group by CAT.cat_nome

Will list the quantity of products for each category.

  • thank you very much! that’s right.

  • For nothing heheh !

  • If possible mark as solution that there is marked as solved... hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.