0

The initial select statement goes like this, and will return X number of rows:

$query = $database->connection->prepare("SELECT * FROM table");
$query->execute();
while ($result = $query->fetch(PDO::FETCH_ASSOC)) {
}

Now I want to delete all of the rows returned in a single statement without looping, but only the exact rows returned since additional records may be inserted during the execution of the script.

  • possible duplicate of [How to delete from select in MySQL?](http://stackoverflow.com/questions/4562787/how-to-delete-from-select-in-mysql) – cmorrissey Oct 21 '14 at 20:01
  • @cmorrissey Nope! not a duplicate! Totally different! – Mr. Cockadookie Oct 21 '14 at 20:06
  • 1
    how is it not a duplicate? you can simply delete all of the rows you want deleted with single MySQL call instead of looping though your results in php ... and I quote `Now I want to delete all of the rows returned in a single statement without looping` – cmorrissey Oct 21 '14 at 20:15
  • What storage engine? If you are using InnoDB then you can use a transaction. Or you can lock the table to prevent new inserts. Other than that, without looping, not sure what you can do (create a table of IDs to delete maybe). what are you doing in the `SELECT` that you couldn't just delete the data right away? – Dan Oct 21 '14 at 20:16
  • @cmorrissey Sounds like cockadookie to me! – Mr. Cockadookie Oct 21 '14 at 20:20
  • @Mr.Cockadookie cmorrisey is right this is a duplicate! – meda Oct 21 '14 at 20:20

0 Answers0