以下是我的查询,我正在尝试更新recods,但是我收到错误:
您无法在子句
中指定更新目标表UPDATE user_payment_info
SET
ammount='110',
status='failed',
transaction_id='0'
WHERE
id=(SELECT id
FROM user_payment_info
WHERE cust_id='771'
ORDER BY id DESC
LIMIT 1)
如何通过从同一个表中获取id来更新记录
如何解决这些mysql错误
您无法在子句
中指定要更新的目标表
有些人可以帮我做这些。
答案 0 :(得分:2)
请改为尝试:
UPDATE user_payment_info AS t1
INNER JOIN
(
SELECT MAX(id) AS MaxId
FROM user_payment_info
WHERE cust_id='771'
) AS t2 ON t1.id = t2.MaxId
SET t1.ammount='110',
t1.status='failed',
t1.transaction_id='0';
答案 1 :(得分:1)
您不必使用子查询,您可以使用带有order by和LIMIT 1的UPDATE查询:
UPDATE
user_payment_info
SET
ammount='110',
status='failed',
transaction_id='0'
WHERE
cust_id='771'
ORDER BY
id DESC
LIMIT 1