I have this query
UPDATE trh_adminLoginDate SET superseded = true WHERE EXISTS (SELECT * FROM trh_adminLoginDate AS a2 WHERE a2.adminId = a.adminId AND a2.loginDate > a.loginDate AND a2.clientPlatform = a.clientPlatform)
and table look like this.
+----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | dateCreated | datetime | NO | | NULL | | | version | int(11) | NO | | NULL | | | dateModified | datetime | NO | | NULL | | | adminId | bigint(20) | NO | MUL | NULL | | | clientPlatform | varchar(255) | YES | | NULL | | | loginDate | datetime | YES | | NULL | | | superseded | tinyint(1) | NO | | NULL | | +----------------+--------------+------+-----+---------+----------------+
When I execute this query I get the below error:
ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause
I can create temporary table and keep the result of the sub-query and then do the UPDATE. But I don't want to do in this way. Can someone suggest me better way of doing this?