I'm trying to select duplicate data from a column based on data from another column. For example, I have a table of events that are either 'IN_PROGRESS' or 'COMPLETE'. They each have an ID. Some of the events have the same ID but different statuses. I am trying to select the data where status = in_progress or status = complete but only if their ids are the same.
This is what I am trying so far:
SELECT id, count (*)
FROM events WHERE status = 'IN_PROGRESS' OR status = 'STARTED'
GROUP BY id HAVING count (*) > 1;
But obviously it only returns the ids rather than the entire row so I can't see all the data. Ultimately I intend to select all of the data in the table while filtering out the duplicates based on the above.
I've started to look into a a join or comparing with a duplicate table but I'm not sure what is the best way to achieve what I need. Can someone please help?
Thanks
status, have all the other fields the same values, if theidis the same?count(distinct status)instead ofcount(*)so as to detect only IDs that have both statuses.