I have a table like this:
Id email Active
---------------------
1 aaa 1
2 aaa 1
3 aaa 0
4 aaa 0
I want to delete duplicate row but if Active have 1/0 value keep 1 value and delete 0 value.
I tried this query
select * FROM tbl_name WHERE Id NOT IN (SELECT Id FROM tbl_name GROUP BY email)
And I expected this result :
Id email Active
---------------------
1 aaa 1
OR
Id email Active
---------------------
2 aaa 1
but actually result was :
Id email Active
---------------------
4 aaa 0
Thanks in advance.
2
Answers
Got to simulate your problem: http://sqlfiddle.com/#!9/67b0ed8/1
And splited to three parts
01 – I updated all your records to inactive
02 – I identified witch records are the same and activate them.
03- I deleted the rest of inactive records
Let me know if it helped you