I have the following table called tbl_test in a MySQL database :
+------+------------+------------+
| name | fav_color | dob |
+======+============+============+
| jane | blue | 1996-07-07 |
+------+------------+------------+
| jane | pink | 1996-07-07 |
+------+------------+------------+
| jane | pink | 2016-07-07 |
+------+------------+------------+
| joe | pink | 2001-07-07 |
+------+------------+------------+
| john | red | 1997-07-07 |
+------+------------+------------+
In English, here's what I want to accomplish:
delete all users with dob < 2001-01-01 but keep a user if there exists another user with the same name AND fav_color whose dob >= 2001-01-01.
So in this example, the jane whose favorite color is blue and john would be deleted.
So far, I've tried:
DELETE FROM tbl_test
WHERE dob < '2000-01-01' AND name, fav_color NOT IN
(SELECT T.name, T.fav_color FROM
(SELECT name, fav_color FROM tbl_test WHERE dob >= '2000-01-01') T);
But MySQL throws a syntax error when I enter this command. Any tips for how I can achieve this?