I have 5 tables in my database : Category1 , Category2 , Category3 , Category4 , Category5
I have a user that might or might not be found on these tables. If he is found , i want to DELETE him from the table.
I could do that with 5 queries like this :
//search if the user is already subscribed in every one of the categories
$stmt = $db->prepare("Select * FROM category1 WHERE deviceUDID = :deviceUDID");
$stmt->execute(array(':deviceUDID' => $deviceUDID));
if($rows_found = $stmt ->rowCount()) {
$stmt = $db -> prepare("DELETE FROM category1 WHERE deviceUDID =:deviceUDID");
$stmt->execute(array(':deviceUDID' => $deviceUDID));
}
Then for category2 :
//search if the user is already subscribed in every one of the categories
$stmt = $db->prepare("Select * FROM category2 WHERE deviceUDID = :deviceUDID");
$stmt->execute(array(':deviceUDID' => $deviceUDID));
if($rows_found = $stmt ->rowCount()) {
$stmt = $db -> prepare("DELETE FROM category1 WHERE deviceUDID =:deviceUDID");
$stmt->execute(array(':deviceUDID' => $deviceUDID));
}
and so on for the rest of the categories..
Would it be possible to search in all these categories with 1 query to make it faster?
But i cant see the logic how something like that could happen.. Any ideas?
EDIT (BONUS PART)
Would be easier ,faster or more efficient to just make a DELETE query every time , even if the user is not there and let the query fail?
Or i should first check every table and if found make a DELETE query?
Which one could be more effective?