Home >Database >Mysql Tutorial >How to Correctly Delete Rows in MySQL Using LEFT JOIN?
Deletion of Rows in MySQL Using LEFT JOIN
You encounter an error while attempting to delete rows from a deadline table based on a LEFT JOIN. The error, which provides little guidance, states:
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 'LEFT JOIN job ON deadline.job_id = job.job_id WHERE status = 'szaml' at line 1
To resolve this issue, you need to specify the table(s) on which the DELETE operation should be applied. The LEFT JOIN clause only affects the selection of rows, not the rows that will be deleted.
Deleting Rows from Deadline
To delete only the deadline rows that meet the specified criteria, use the following query:
DELETE `deadline` FROM `deadline` LEFT JOIN `job` ....
Deleting Rows from Deadline and Job
To delete both the deadline and job rows for the matching criteria, use the following query:
DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` ....
Deleting Rows from Job
To delete only the job rows for the matching criteria, use the following query:
DELETE `job` FROM `deadline` LEFT JOIN `job` ....
The above is the detailed content of How to Correctly Delete Rows in MySQL Using LEFT JOIN?. For more information, please follow other related articles on the PHP Chinese website!