loudking loudking - 5 months ago 11
SQL Question

SQL to find players who play one game

Given

create table account (
id int not null,
name varchar(100),
country varchar(100),
primary key (id)
);

create table score (
id int not null,
game_name varchar(100),
score int
);


How do I find accounts who played only one game please?
account.id should match score.id. Thanks.

Answer

If I understood your requirement correctly, then you look for something like this:

SELECT *
FROM account
WHERE id IN (SELECT id
             FROM score
             GROUP BY id
             HAVING COUNT(*) = 1)