I'm really stuck at the moment, as my query works, but only with some sample data, in the actual database with 15'000 clients I don't even get a response in time.
I have the following table:
-Client-
id
firstname
lastname
Now my query has to get all possible duplicates and list them, so lets say we have Client A with id 1, B with id 2 and C with id = 3 that have the same first- and lastname. The output should look like this:
id | duplicateID | client | duplicate
1 | 2 | A | B
1 | 3 | A | C
2 | 3 | B | C
My query looks like this:
SELECT
c.id AS clientID,
d.id AS duplicateID,
CONCAT(c.firstname, ' ', c.lastname) AS fullName
FROM Client AS c
JOIN Client AS d
ON d.lastname = c.lastname
AND d.firstname = c.firstname
AND d.id != c.id
AND d.id > c.id
ORDER BY fullName, c.id
Is there any way to increase the performance without losing any results? I looked into this answer, but there I only get one duplicate per client, where I want all of the duplicates.
Any help or tip is appreciated, thanks
Edit: SQL Fiddle as requested