I want to delete certain items from the database. I have the following query:
SELECT *
FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
This works, and returns 2 results.
Now I want to turn this SELECT
query into a DELETE
query. However, the following doesn't work:
DELETE FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
MySQL throws the following error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE entries.sheetID = sheets.id AND sheets.clientID = 13' at line 1
What am I doing wrong here?
MySQL 4 and up supports deleting from multiple tables at once, using the following syntax:
DELETE sheets, entries
FROM sheets, entries
WHERE entries.sheetID = sheets.id AND sheets.clientID = 13
If you're using MySQL below version 4, then you need to delete rows from one table at a time, and you can use one of the other solutions posted here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With