0

当我运行这个:

DELETE FROM folders AS fo
LEFT OUTER JOIN files AS fi 
ON fo.folderId = fi.folderId
WHERE fi.folderId IS NULL AND (fo.folderId IN (63,1000))

...我收到语法错误:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“AS fo LEFT OUTER JOIN files AS fi ON fo.folderId = fi.folderId WHERE fi.fold”附近使用正确的语法

该代码基于SELECT返回预期行的查询。错误信息的原因是什么?

4

2 回答 2

1
DELETE
  FROM folders fo
 WHERE NOT EXISTS (SELECT 1
                     FROM files fi
                    WHERE fi.folderId = fo.folderId)
   AND fo.folderId IN (63, 1000)
于 2013-03-15T11:22:21.617 回答
1

它“不起作用”并不奇怪。当我运行您的代码时,出现语法错误:

SQL 错误 (1064):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“AS fo LEFT OUTER JOIN files AS fi ON fo.folderId = fi.folderId WHERE fi.fold”附近使用正确的语法

正确的语法是:

DELETE fo -- Note I've added table name
FROM folders AS fo
LEFT OUTER JOIN files AS fi 
ON fo.folderId = fi.folderId
WHERE fi.folderId IS NULL AND (fo.folderId IN (63,1000));
于 2013-03-15T11:31:02.563 回答