Deleting rows with MySQL LEFT JOIN

Posted by fabrik on Stack Overflow See other posts from Stack Overflow or by fabrik
Published on 2010-05-04T06:20:32Z Indexed on 2010/05/04 6:28 UTC
Read the original article Hit count: 286

Filed under:
|
|

Hello!

I have two tables, one for job deadlines, one for describe a job. Each job can take a status and some statuses means the jobs' deadlines must be deleted from the other table.

I can easily SELECT the jobs/deadlines that meets my criteria with a LEFT JOIN:

SELECT * FROM `deadline` LEFT JOIN `job` ON deadline.job_id = job.job_id WHERE `status` = 'szamlazva' OR `status` = 'szamlazhato' OR `status` = 'fizetve' OR `status` = 'szallitva' OR `status` = 'storno'

(status belongs to job table not deadline)

But when i'd like to delete these rows from deadline, MySQL throws an error. My query is:

DELETE FROM `deadline` LEFT JOIN `job` ON deadline.job_id = job.job_id WHERE `status` = 'szamlazva' OR `status` = 'szamlazhato' OR `status` = 'fizetve' OR `status` = 'szallitva' OR `status` = 'storno'

MySQL error says nothing:

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

How can i turn my SELECT into a working DELETE query?

Thanks, fabrik

© Stack Overflow or respective owner

Related posts about mysql

Related posts about left-join