I am to "steal" an answer I found in the OS in English ;)
You should group the records. I think we can ignore the repeated Ids (let me know if that’s not convenient). So we will 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 getting a single ID for each group of duplicate records.
In practice it happens that each information distinct from the system will be obtained. And for each group of repeated information, only the smallest ID (or larger if you use MAX instead of MIN) will be obtained.
When you have these results, you will have two alternatives to fulfill your goal:
You can export the result of this query. You will only have different data in the export result;
The least recommended way is to delete all repeated records from the table. This takes courage as any error can erase data beyond the ones you want to delete. I recommend having a backup if you want to go this way.
The command is something like this:
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 records from 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 ID’s of the repeated elements will be null. The delete command will remove these records from the table.
Welcome to Stack overflow. The way your question is it provides little detail to help you. Try to inform in detail what you have already tried. Start by doing a [tour] and read the guide [Ask].
– gmsantos
Ah, please insert also via the link [Edit] which database you are using.
– gmsantos
The bank is the sql gmsantos is there in the title. Sorry for my lack of experience here on the site I am even beginner.
– Lucas Vasconcelos
Lucas, no problem, with time you get the hang of it. You refer to Microsoft SQL Server?
– gmsantos
Yes. I even put an example there of how the table is.
– Lucas Vasconcelos
you tried to use group by?
– haykou
I have never used "nickname. *" with DISTINCT. Enter the name of all fields -
SELECT DISTINCT ID, Nome, Idade INTO Temp FROM tabela
that should work.– Caffé