0

The following

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

understandably returns

Operand should contain 1 column(s)

How do you fix it ?

2 Answers 2

1

You don't need to select the count in the subquery. Just use the count explicitly in the HAVING clause:

delete from child N
where parent_id in
(
    select parent_id
    from parent
    group by other_attribute
    having count(*) > 1
)
Sign up to request clarification or add additional context in comments.

Comments

0

Modify your query to be

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

(OR)

Make it a JOIN query saying

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.