Delete duplicate or same records from database table its a very common task ,If you want delete duplicate or common records or rows form your database table then you can go with below simple query.
1. Create tbl_user
2. If you want to keep the row with the lowest
Output will be
3. If you want to keep the row with the highest
Output will be
3. When I did it, I found that unless I also included AND n1.id <> n2.id, it deleted every row in the table.
1. Create tbl_user
2. If you want to keep the row with the lowest
id
value:DELETE a FROM tbl_users a INNER JOIN tbl_users b ON a.username = b.username WHERE a.id > b.id
id
value:DELETE a FROM tbl_users a INNER JOIN tbl_users b ON a.username = b.username WHERE a.id < b.id
3. When I did it, I found that unless I also included AND n1.id <> n2.id, it deleted every row in the table.
Post a Comment