loudking
loudking

Reputation: 115

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.

Upvotes: 0

Views: 483

Answers (1)

Giorgos Betsos
Giorgos Betsos

Reputation: 72175

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)

Upvotes: 2

Related Questions