I have a table like this:
// users
+----+----------+-------+---------------------+
| id | name | age | some other cols .. |
+----+----------+-------+---------------------+
| 1 | Ali | 15 | .. |
| 2 | John | 15 | .. |
| 3 | Ali | 22 | .. |
| 4 | Martin | 18 | .. |
| 5 | Ali | 15 | .. |
| 6 | John | 30 | .. |
| 7 | John | 15 | .. |
+----+----------+-------+---------------------+
I want to add a composite unique index on name, age columns. Currently, it gives me there are duplicates rows error. Already, I was using INSERT IGNORE .. to do this job but sadly IGNORE is no longer supported in MySQL.
Anyway, any idea how can I remove rows that have the same values on both name and age columns and keep just one of them (one of rows)? In other words, I want to remove all rows that have the same value on name and age columns except one of them.
So, here is the expected result:
// users
+----+----------+-------+---------------------+
| id | name | age | some other cols .. |
+----+----------+-------+---------------------+
| 1 | Ali | 15 | .. |
| 2 | John | 15 | .. |
| 3 | Ali | 22 | .. |
| 4 | Martin | 18 | .. |
| 6 | John | 30 | .. |
+----+----------+-------+---------------------+
Any idea how can I do that?