从具有多列的select中删除MySql?

时间:2016-06-04 12:29:34

标签: mysql

以下

delete from child N
where parent_id in
(select parent_id , count(*) c
from parent
group by other_attribute  having c > 1 )

可以理解地返回

Operand should contain 1 column(s)

你如何解决?

2 个答案:

答案 0 :(得分:1)

您无需在子查询中选择计数。只需在HAVING子句中明确使用计数:

delete from child N
where parent_id in
(
    select parent_id
    from parent
    group by other_attribute
    having count(*) > 1
)

答案 1 :(得分:0)

将您的查询修改为

delete from child 
where parent_id in (
select parent_id 
 from parent   
group by other_attribute  
having count(*) > 1 )

(OR)

JOIN查询说成

delete child 
from child
join (    
select parent_id 
from parent   
group by other_attribute  
having count(*) > 1 ) xxx on child.parent_id = xxx.parent_id;