I want to find all users whose name appears at least twice in my User table. "email" is a unique field, but the combination of "firstName" and "lastName" is not necessarily unique.
So far, I have come up with the following query, which is very slow, and I'm not even sure if it is correct. Please let me know how best to rewrite this.
SELECT CONCAT(u2.firstName, u2.lastName) AS fullName FROM cpnc_User u2 WHERE CONCAT(u2.firstName, u2.lastName) IN ( SELECT CONCAT(u2.firstName, u2.lastName) AS fullNm FROM cpnc_User u1 GROUP BY fullNm HAVING COUNT(*) > 1 )
Also note that the above returns a list of names that appear at least twice (I think so, one way or another), but I really want this to be a complete list of all user ID fields for these names. Therefore, each name, since it appears at least twice, will be associated with at least two fields of the "id" primary key.
Thanks for any help! Jonah
source share