Skip to content
Advertisement

MySQL – Join 2 tables and count number of entries

I’m trying to join 2 tables and count the number of entries for unique variables in one of the columns. In this case I’m trying to join 2 tables – patients and trials (patients has a FK to trials) and count the number of patients that show up in each trial. This is the code i have so far:

The Outcome I’m trying to acheive is:

I’m completely new to sql and have been struggling with the syntax compared to scripting languages.

Advertisement

Answer

It’s not 100% clear from your question of the names of your columns however you are after a basic aggregation. Adjust the names of the columns if necessary:

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