我有一个表'lot_login_tracking',其中包含列:
lot_i_login_id 是主键&汽车公司
lot_i_login_id lot_i_user_id lot_d_login_stamp lot_d_logout_stamp
1 1296 2013-07-11 09:18:32 NULL
2 1296 2013-07-11 09:55:38 NULL
3 1296 2013-07-11 09:57:38 NULL
我在用户注销时执行跟随查询:
UPDATE lot_login_tracking SET lot_d_logout_stamp = "2013-07-11 19:28:21"
WHERE lot_i_login_id = ( SELECT max(lot_i_login_id)
FROM lot_login_tracking WHERE lot_i_user_id = 1296)
收到错误:
错误1093(HY000):您无法指定目标表 'lot_login_tracking'用于FROM子句中的更新。
如何解决?
答案 0 :(得分:1)
另一种方法是使用join,
UPDATE lot_login_tracking a
INNER JOIN
(
SELECT max(lot_i_login_id) m
FROM lot_login_tracking
WHERE lot_i_user_id = 1296
) b ON a.lot_i_login_id = b.m
SET a.lot_d_logout_stamp = '2013-07-11 19:28:21'