1DELETE t1 FROM subscriptions t1
2INNER JOIN subscriptions t2
3WHERE
4 t1.id < t2.id AND
5 t1.user_id = t2.user_id AND t1.name = t2.name
1DELETE FROM table_name WHERE id
2 NOT IN ( SELECT id FROM table_name
3 GROUP BY field_1, field_2)
1DELETE FROM CONTACTS
2WHERE ID NOT IN
3 (SELECT *
4 FROM (SELECT max(ID)
5 FROM CONTACTS
6 GROUP BY EMAIL) t);
7 -- ⇓ Test it ⇓ (Fiddle source link)
1 delete test
2 from test
3 inner join (
4 select max(id) as lastId, email
5 from test
6 group by email
7 having count(*) > 1) duplic on duplic.email = test.email
8 where test.id < duplic.lastId;
1DELETE t1 FROM contacts t1
2INNER JOIN contacts t2
3WHERE
4 t1.id < t2.id AND
5 t1.email = t2.email;Code language: SQL (Structured Query Language) (sql)