title: MySQL - select and then delete, preferably in a single query
body: <p>We often need to do following, retrieve product ids for a user and then delete them from the database. </p>
  
  <pre><code>select id from mytable where user=123;
  </code></pre>
  
  <p>and then we delete those id returned from query above:</p>
  
  <pre><code>delete from mytable where id in (1, 5, 6, 7);
  </code></pre>
  
  <p>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. </p>
  
  <p>Is there a better way to achieve it? </p>
  
  <p>Thanks</p>
  
  <p><strong>Edit</strong>: some of you have answered, 
     delete from mytable where user=123;</p>
  
  <p>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. </p>