I am "stealing" an answer I found in the English OS ;)
You must group the records. I think we can ignore the repeated ID's (let me know if that does not come in handy). So we'll use all fields except the ID field. Something like:
SELECT MIN(ID) as ID, Nome, Idade
FROM Temp
GROUP BY Nome, Idade
Note that you can use MAX instead of MIN ... What matters is to get a single ID for each duplicate group of records.
In practice it happens that each distinct information of the system will be obtained. And for each group of multiple repeated information, only the smallest ID (or greater, if you use MAX instead of MIN ) will be obtained.
When you have these results, you have two alternatives to fulfill your goal:
-
You can export the result of this query. You will only have the distinct data in the export result;
-
The least recommended way is to delete all repeated records from the table. This requires courage, since any error can delete data other than the one you want to delete. I recommend having a backup if you want to go this way.
The command is anything like the following:
DELETE *
FROM Temp
LEFT OUTER JOIN (
SELECT MIN(ID) as ID, Nome, Idade
FROM Temp
GROUP BY Nome, Idade
) as RegistosAManter ON
Temp.ID = RegistosAManter.ID
WHERE
RegistosAManter.ID IS NULL
The query from FROM retrieves all the records in the table. The ID's of each record appear twice (because we are using a JOIN), but on the right side of the result the IDs of the repeated elements will be null. The delete command will remove these records from the table.