Reputation: 35
Is it possible to SELECT
specific rows and DELETE
the selected result in ONE request?
$res = $Connection->query("SELECT * FROM tasks");
if($res->num_rows > 0){
while($row = $res->fetch_assoc()){ ...
The problem is that I have limited Number of queries to my SQL database and I want to minimize it as mush as possible.
Upvotes: 2
Views: 54
Reputation: 400
You can't do that using the regular mysql-api in PHP. Just execute two queries. The second one will be so fast that it won't matter. This is a typical example of micro optimization. Don't worry about it. (So timing doesn't matter much)
For the record, since you are worried about the number of queries, it can be done using mysqli and the mysqli_multi_query-function.
P.S. - I haven't tried this, but since this mysql_multi_query
is there in the documentation, it might help... :)
Upvotes: 1
Reputation: 26
Both SELECT and DELETE need one request individually. And there is no SQL can do this work in the official documents.
Upvotes: 1