sql语法错误db\u query

gudnpqoy  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(318)

我试图从Adminer4.6.2运行以下查询,它给出了含糊不清的“语法错误”,没有进一步的细节:

db_query("DELETE FROM {field_collection_item} WHERE field_name NOT IN (SELECT field_name FROM {field_config} WHERE type = 'field_collection')");

我也试过:

DELETE FROM {field_collection_item} WHERE field_name NOT IN (SELECT field_name FROM {field_config} WHERE type = 'field_collection')

但它返回相同的语法错误。

9njqaruj

9njqaruj1#

不要使用双引号,使用2个单引号 '' ,筛选条件要求值用单引号括起来。通过使用print@sql验证代码总是一个好的实践
前任:

DECLARE @sql VARCHAR(max)

SET @sql = 'DELETE FROM [field_collection_item] WHERE field_name
               NOT IN (SELECT field_name FROM [field_config] WHERE type = ''field_collection'')'

PRINT @sql

印刷品:

DELETE FROM [field_collection_item] WHERE field_name NOT IN 
   (SELECT field_name FROM [field_config] WHERE type = 'field_collection')

相关问题