Skip to content
Advertisement

List and Count items with a JOIN with SQL

I’m trying to create a basic rapport from these 2 tables:

Table Products

Table Categories

What I needed is this output:

I would like a report listing all the categories from Categories but only when product from Products has a link (with is the case form Fruits but not for Other).

This is where I am actually:

Anyone to help me with this please ?

Thanks.

Advertisement

Answer

You are pretty close. You need to get rid of the garbage in the query and use a group by:

Notes:

  • SELECT * is not appropriate for an aggregation query. What you want to select is.
  • This puts the count in a separate column which seems to be your intention, despite the sample results.
  • COUNT(pro_name in sum) doesn’t make sense.
  • as sum doesn’t make sense.
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement