I’m having a problem grokking this code
SELECT * FROM sometable WHERE EXISTS (
SELECT 1 FROM sometable
GROUP BY relevant_field
HAVING count(*) > 1)
If I use a JOIN, I specify the link explicitly, but here I don’t so I don’t have clear concept of what’s happening inside MySQL.
How does MySQL know how to link the rows from the inner sometable to the outer sometable?
Your query as it is will either returns all rows from
sometableor no rows at all, depending on whether the parenthesized SELECT will return rows or not.In other words, MySQL does not know how to and will not link the rows from the inner to the outer sometable in this particular query.
The equivalent to a join would be: