Reputation: 13
How do I query that I get a distinct clubName based on my query? Below is the website to demo the sql query.
http://www.sqlfiddle.com/#!2/54be8b/6
Here is the query used in the SQL fiddle:
SELECT DISTINCT c.ClubName, c.*, p.*
from Club c inner join Persons p on p.clubName = c.clubName;
Output should be
ManUtd
Barcelona
with 4 rows
Upvotes: 0
Views: 68
Reputation: 22530
If you are only interested in getting distinct clubName's,
SELECT DISTINCT c.ClubName
FROm Club c inner join Persons p on p.clubName = c.clubName;
This gives you
CLUBNAME
Man Utd
Barcelona
If, however, you include all other columns in the SELECT DISTINCT
statement as you did in the OP,
SELECT DISTINCT c.ClubName, c.*, p.*
from Club c inner join Persons p on p.clubName = c.clubName;
then, there may be multiple DISTINCT rows corresponding to the same clubName
, and SQL is correct to give you:
CLUBNAME ID LASTNAME FIRSTNAME
Man Utd 1 Maria Di
Man Utd 1 Rooney Wayne
...
Upvotes: 1