A while back I came onto this site to try and find a query, and ended up with this below. What it does, and what I need it to do, is to look into the table ‘data’ and return the first name, last name, and date of birth of any customer who has been treated at two different diagnosis_locations. It works.
SELECT firstname, lastname, date_of_birth
FROM `data`
WHERE diagnosis_location IN (SELECT DISTINCT Diagnosis_location
FROM `data`)
GROUP BY firstname, lastname, date_of_birth
HAVING COUNT(DISTINCT diagnosis_location) >= 2
However, now I need to take this same query and get an identical result without using any subqueries. Could anyone help me here? Or at least give me some pointers?
From what I see your query returns records where
diagnosis_locationfield is not equal null, so you can rewrite it asWHERE diagnosis_location IS NOT NULL