You have two tables:
DELETE b FROM BLOB b LEFT JOIN FILES f ON f.id = b.fileid WHERE f.id IS NULL
<告> Warning:
DELETE FROM BLOB WHERE NOT EXISTS(SELECT NULL FROM FILES f WHERE f.id = fileid)
When performing a delete operation, make sure they execute them in affairs. This allows you to roll back to change when any error occurs, thereby minimizing the risk of data loss.
The above is the detailed content of How to Delete Orphan Rows in SQL Using LEFT JOIN, NOT EXISTS, or NOT IN?. For more information, please follow other related articles on the PHP Chinese website!