Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sql query COUNT number of occurences when joining a table

Im trying to return the names of all members that have registered a tasting of a coffe in my DB, and count number of tasting each name has left.

select bruker.navn, COUNT(*) from kaffesmaking inner join bruker on kaffesmaking.bruker_epost = bruker.epost

table "user" has the columns

name, email , password

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

table "tasting (alias kaffesmaking) has the columns:

id, note, date, score, user_email, coffename

I want a list displaying

names with numbers of tastings done by that particular user.

i.e

John Johnson 5
Jessie ashford 3
Paul newman 8

Where the number represents the number of rows that specific user has added in the tasting table.

Any help would be appreciated

>Solution :

You were almost there, you need to add a "group by" to your SQL

SELECT bruker.navn
     , COUNT(*) as tastings
  FROM kaffesmaking
  INNER JOIN bruker
       ON kaffesmaking.bruker_epost = bruker.epost;
  group by bruker.navn;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading