I am having trouble and need some help finding a correct SQL query. Here is my code so far:
SELECT firstname, lastname, date_of_birth
FROM `data`
WHERE firstname IN (SELECT firstname
FROM `data`
WHERE diagnosis_location = 'Mayo')
AND lastname IN (SELECT lastname
FROM `data`
WHERE diagnosis_location = 'Mayo')
AND date_of_birth IN (SELECT date_of_birth
FROM `data`
WHERE diagnosis_location = 'Mayo')
AND firstname IN (SELECT firstname
FROM `data`
WHERE diagnosis_location = 'Lahey')
AND lastname IN (SELECT lastname
FROM `data`
WHERE diagnosis_location = 'Lahey')
AND date_of_birth IN (SELECT date_of_birth
FROM `data`
WHERE diagnosis_location = 'Lahey')
Yes, it’s a monster of a query and probably isn’t all that efficient. But what I am trying to do is only return the first name, last name, and date of birth of all patients diagnosed at both the ‘Mayo’ location and the ‘Lahey’ location. This query does return those patients, but it returns multiple rows of the same exact data.
How could I limit it so duplicates of the same exact results are trimmed out?
Use: