1

我有一个包含列的表'lot_login_tracking':
lot_i_login_id is primary key & auto inc

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)

并得到一个错误:

ERROR 1093 (HY000): 您不能在 FROM 子句中指定目标表 'lot_login_tracking' 进行更新。

如何解决?

4

1 回答 1

1

另一种方法是使用连接,

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'
于 2013-07-11T14:27:56.770 回答