I have a table like this:
+----------------------------+
| user | date | current |
+----------------------------+
| 1 | 20010101 | 1 |
| 1 | 20020202 | 1 |
| 1 | 20030303 | 1 |
| 2 | 20010101 | 1 |
| 2 | 20020202 | 1 |
+----------------------------+
I would like to update the current column such that only each user's most recent entry has a 1.
I had planned:
UPDATE table t1 SET current = 0
WHERE EXISTS (
SELECT id
FROM table t2
WHERE t2.user = t1.user
AND t2.date > t1.date )
)
But this tells me ERROR 1093 (HY000): You can't specify target table 't1' for update in FROM clause
Is there a way around this limitation of MySQL?
