Skip to content
Advertisement

Using 2 “Group By” in one SQL Query

I got 3 tables that look like this:

Locations: id,name

Events: id,name,locationid

Participants: id,name,eventid

What I want is a query, that returns all locations, a count of the events linked to it and a count of the participants (indirectly) linked to a location.

This is what I’m trying, but this query returns a row for each tournament, instead of grouping it:

Advertisement

Answer

One method is to use count(distinct) instead of count().

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