gpt4 book ai didi

mysql - 我的 SELECT 语句有效,但我无法删除

转载 作者:行者123 更新时间:2023-11-29 01:39:09 24 4
gpt4 key购买 nike

我有一个有效的 SQL 查询,它返回需要从数据库中删除的信息。我很难使用此信息来删除记录。

我正在使用 mySQL 数据库,并尝试使用 HeidiSQL 进行这些更改。

用于选择数据的代码是:

SELECT * 
FROM users u
WHERE NOT EXISTS
(SELECT 1
from users_classdetails uc
WHERE u.id = uc.userID
AND dateEntered > DATE_SUB(NOW(),INTERVAL 3 YEAR) )
AND bestcontact = ""

我希望能够使用类似的东西:

DELETE 
FROM users u
WHERE NOT EXISTS
(SELECT 1
from users_classdetails uc
WHERE u.id = uc.userID
AND dateEntered > DATE_SUB(NOW(),INTERVAL 3 YEAR) )
AND bestcontact = ""

但我看到错误 1064,说明我的语法错误。它指出 WHERE NOT EXISTS ( SELECT 1 from users_classdetails 作为问题。我不确定为什么它对 SELECT 有效但对 DELETE。如有任何帮助,我们将不胜感激。

最佳答案

you can't use table aliasing and must use the full table name in the NOT EXISTS part of the query.

Source

关于mysql - 我的 SELECT 语句有效,但我无法删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576263/

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