I have the following table called tbl_test in a MySQL database:
+------+----------+
| user | dob |
+------+----------+
| john | 1/10/96 |
| jane | 3/4/97 |
| jill | 1/8/96 |
| jack | 2/9/00 |
| jane | 12/14/07 |
| john | 1/11/98 |
+------+----------+
In English, here's what I want to accomplish:
delete all users with dob < 1/1/00 but keep a user if there exists another user with the same name whose dob >= 1/1/00.
In this example, the johns and jill would be deleted and the janes and jack would stay.
I've come up with the following sql command to do this:
DELETE from tbl_test
WHERE dob < '2000-01-01'
AND name NOT IN (SELECT name from tbl_test WHERE dob >= '2000-01-01')
And MySQL throws this error: You can't specify target table 'tbl_test' for update in FROM clause.
How can I modify the above command to make it legal?