Home > database >  Query for people who have more than one appointment
Query for people who have more than one appointment

Time:11-25

ID Name Date Office
2 Paul 2-2-21 Dentist
5 Jake 2-2-21 EMERG
1 Phil 2-2-21 Dentist
1 Phil 2-2-21 Dentist
2 Paul 3-2-21 Ortho

i made thetable i'm a new at SQL and wondering to how can i make a query that will return the ID and names of the people who are having mroe than one appointment i know this is bigginer but iam confused my approach

SELECT id,name FROM worktable DISTINCT date > 2

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

CodePudding user response:

SELECT ID,Name,Date,Office
FROM 
(
SELECT *,row_number() over (partition by Name) as row_num FROM worktable
) a
where row_num >= 1

CodePudding user response:

You could try using a join with a subquery that return the name with more then an appointent

select id, name from worktable w
inner join (
SELECT name 
FROM worktable 
group by name 
having count( date) > 1 ) a on a.name = w.name
  • Related