Home > Mobile >  SQL Query to find people who have interviews in different rooms inany days
SQL Query to find people who have interviews in different rooms inany days

Time:11-24

Name Date Room
Jerry 2-2-21 D
Sam 2-2-21 A
Sarah 2-2-21 A
Will 3-2-21 B
Sam 4-3-21 D
Will 2-2-21 B
Jerry 2-2-21 D

Hello, (apologise for my bad english) i made the previous table i'm a new at SQL and wondering to how can i make a query that will return the names of the people who had interviews in different rooms regardless of the day so will would not come up since he had interviews in the same rooms

my approach

SELECT name FROM worktable DISTINCT room > 2

i dont' know what else to do thank you any help appreciated

CodePudding user response:

You should use, HAVING and GROUP BY :

SELECT name
FROM worktable
GROUP BY name
HAVING COUNT(name) > 1;

CodePudding user response:

In addition to @Beso answer I would also use DISTINCT in COUNT to be sure there are different rooms.

SELECT name
FROM worktable
GROUP BY name
HAVING COUNT(DISTINCT name) > 1

In this case only Sam will be included in the select output.

  • Related