我需要从我的数据库中删除一些特定的重复项。我创建了一个查询来查找我需要的记录,但是当它作为子查询运行时出现错误“operand should contain 1 column
”我不知道如何获取我的具体信息需要同时只选择一个列。
查询是:
delete
from products
where id in (SELECT *
FROM products
GROUP BY part_number
HAVING count(*) > 1 and manufacturer_id="4146"
)
知道如何让它工作吗?
最佳答案
在你的子查询中你需要选择 id 一列
delete
from products
where id IN (SELECT id
FROM products
WHERE manufacturer_id="4146"
GROUP BY part_number
HAVING count(*) > 1
)
同时从同一个表中获取 id 会给你另一个错误无法指定目标表你需要为你的子查询提供新的别名
delete
from products
where id IN
(SELECT t.id FROM (
(SELECT id
FROM products
WHERE manufacturer_id="4146"
GROUP BY part_number
HAVING count(*) > 1 ) t
)
关于mysql - DELETE 查询给出 "operand should contain 1 column"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21711335/