mysql如何在where子句中使用相同的子查询更新表
以下是我的查询,我正在尝试更新记录,但出现错误: 不能在from子句中指定更新的目标表mysql如何在where子句中使用相同的子查询更新表,mysql,Mysql,以下是我的查询,我正在尝试更新记录,但出现错误: 不能在from子句中指定更新的目标表 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
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错误
不能在from子句中指定更新的目标表
有人能帮我做这些吗。您不必使用子查询,您可以使用order by和LIMIT 1的更新查询:
UPDATE
user_payment_info
SET
ammount='110',
status='failed',
transaction_id='0'
WHERE
cust_id='771'
ORDER BY
id DESC
LIMIT 1
您不必使用子查询,可以使用order by和LIMIT 1的更新查询:
UPDATE
user_payment_info
SET
ammount='110',
status='failed',
transaction_id='0'
WHERE
cust_id='771'
ORDER BY
id DESC
LIMIT 1
请尝试以下方法:
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';
请尝试以下方法:
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';
在中不要使用排序依据subquery@Saty我也尝试删除order by,但我不会在中使用
order by
subquery@Saty我也试图通过删除订单,但我不会工作