I am using PostgreSQL database. I have the data like below.
id name1 name2 modified_date
- - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 Balfe | Pat | 2010-10-01 17:48:44.804823
41 Battigan | David |
42 Balfe | Pat | 2010-10-01 12:46:49.627593
44 Balfe | Pat | 2010-10-04 14:04:28.72415
45 Balfe | Pat |
46 Balfe | Pat | 2010-10-01 17:30:39.193153
47 Balfe | Pat |
I want to delete some rows from the table. The conditions to delete are:
- It will delete duplicate records with
modified_date = Null
–> one copy of duplicate records should not be deleted. - Records with modified date should not be deleted although they are duplicate.
From the table above, the record with id 47 or 45 should be deleted.
This one should delete all records with
modified_date Is Null, where another record with the samename1andname2exists, which also hasmodified_date Is Null.The record with the lowest
idwill not be deleted.