Skip to content
Advertisement

Get count and grouping of foreign key

I have this product_user table which has foreign key product in it.

enter image description here

I need to group and count all of the products from that table with the same IDs and get that product name so result of the query could be:

I think I could use join table and one of many tries was:

I am new at writing SQL queries so any hint can be useful.

Advertisement

Answer

This:

Should be:

Optionally change this:

To this:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement