We often need to do following, retrieve product ids for a user and then delete them from the database.
select id from mytable where user=123;
and then we delete those id returned from query above:
delete from mytable where id in (1, 5, 6, 7);
It is possible that while select is returning data from server to client, a new record for that user is inserted and hence we are selectively deleting ids.
Is there a better way to achieve it?
Thanks
Edit: some of you have answered, delete from mytable where user=123;
but it's a wrong answer as a new row might be inserted between mysql server completed the query and mysql client yet to receive response from the server.