Using JOIN to find duplicates in another table taking too long
I can't imagine that the first query would work.  The subquery needs count but that is not available until the entire query is finished.  The outer select can't move forward until the subquery provides the existence of each row.
Try to turn the entire query into a JOIN; no subquery.  In the ON you can test for one &quot;people_id&quot; being less than another -- this implies that there are two rows.