gpt4 book ai didi

mysql - 如果在 Mysql 中找到第二行,则删除它

转载 作者:行者123 更新时间:2023-11-29 15:58:18 25 4
gpt4 key购买 nike

如果商家有 2 行,我会尝试删除 MySql 中的一行。删除哪一行并不重要。

当我运行时:

SELECT * FROM products.merchant_configs WHERE `configKey` = 'CHECK_BALANCE_SUBJECT'
AND merchantId = 6;

我明白了:

enter image description here

现在我尝试删除其中一行:

DELETE FROM products.merchant_configs
WHERE id = (
SELECT id FROM products.merchant_configs WHERE `configKey` = 'CHECK_BALANCE_SUBJECT'
AND merchantId = 6
LIMIT 2 OFFSET 1
);

我收到错误:

Error Code: 1093. You can't specify target table 'merchant_configs' for update in FROM clause

发生什么事了?

最佳答案

将查询嵌套在另一个选择语句中:

DELETE FROM products.merchant_configs
WHERE id = (SELECT t.id FROM (
SELECT id FROM products.merchant_configs WHERE `configKey` = 'CHECK_BALANCE_SUBJECT'
AND merchantId = 6
LIMIT 2 OFFSET 1
) t);

请参阅demo .

关于mysql - 如果在 Mysql 中找到第二行,则删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56340913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com