Hello all,
I want a SQL code to delete all the duplicate records but one where the record's field2 value is maximum.
For eg:
Field1 Field2
55 33
44 22
222 22
44 11
55 56
55 31
So if I run the query the final table should look like
Field1 Field2
44 22
222 22
55 56
I found SQL code to delete all the duplicate records but not where I can put a condition on the second field. Also, I'm very new at SQL so please help me.
Edit 1: I'm checking the duplicate records for field1
I want a SQL code to delete all the duplicate records but one where the record's field2 value is maximum.
For eg:
Field1 Field2
55 33
44 22
222 22
44 11
55 56
55 31
So if I run the query the final table should look like
Field1 Field2
44 22
222 22
55 56
I found SQL code to delete all the duplicate records but not where I can put a condition on the second field. Also, I'm very new at SQL so please help me.
Code:
DELETE *
FROM Table1
WHERE (((Table1.Field1) In (SELECT [Field1] FROM [Table1] As Tmp GROUP BY [Field1] HAVING Count(*)>1 )));
Edit 1: I'm checking the duplicate records for field1