Delete the row of no matching in the SQL table
You have two tables:
<code class="language-sql">DELETE b FROM BLOB b LEFT JOIN FILES f ON f.id = b.fileid WHERE f.id IS NULL</code>
Warning:
<code class="language-sql">DELETE FROM BLOB WHERE NOT EXISTS(SELECT NULL FROM FILES f WHERE f.id = fileid)</code>
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!