codice:
/* 1. Query heading */
SELECT
* /* Remember to never use SELECT * and write out the field names */
FROM
/* 2. Table with duplicates */
mr_link
WHERE
EXISTS (
SELECT
NULL
FROM
/* 3. Table with duplicates, with an alias */
mr_link b
WHERE
/* 4. Join each field with *itself*. These are fields that could be Primary Keys */
b.[pagina] = mr_link.[pagina]
AND b.[id_parola] = mr_link.[id_parola]
AND b.[selezione] = mr_link.[selezione]
AND b.[id] = mr_link.[id]
GROUP BY
/* 5. I must GROUP BY these fields because of the HAVING
clause and because these are the possible PK */
b.[pagina], b.[id_parola], b.[selezione], b.[id]
HAVING
/* 6. This is the determining factor. We can control our
output from here. In this case, we want to pick records
where the ID is less than the MAX ID */
mr_link.[id_link] < MAX(b.[id_link])
)
id_link è la chiave primaria. La query la eseguo con SQL QUERY ANALYZER