MySQL Forums
Forum List  »  Newbie

Re: Delete and select in the same query
Posted by: Peter Brawley
Date: September 29, 2014 12:19PM

Yes, sorry, that's the select cmd ...

select id_comment from comments where user_id=N
union
select id_comment from comments a
join comments b on a.id_parent=b.id_comment
where b.user_id=N;

The simplest way to delete those rows is probably to run these two deletion commands ..

delete from comments where user_id=N

delete a
from comments a join comments b on a.id_parent=b.id_comment
where b.user_id=N;

> why you use union?

Union does exclusive or on statement results (union all does inclusive or). It can be simpler & more efficient to do the ORing at statement level rather than in the Where clause.

Options: ReplyQuote


Subject
Written By
Posted
September 28, 2014 02:59AM
Re: Delete and select in the same query
September 29, 2014 12:19PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.