Removing Rows with MySQL LEFT JOIN
Problem:
You have two tables: one for job deadlines and another for job descriptions. You need to delete deadline entries based on the statuses in the job description table. Using a LEFT JOIN for selection works, but performing a DELETE raises a syntax error.
Query for Selection:
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'
Solution:
To perform the DELETE operation, you must explicitly specify the tables you want to delete rows from. Here are the possible options:
Delete Only Deadline Rows:
DELETE `deadline` FROM `deadline` LEFT JOIN `job` ....
Delete Both Deadline and Job Rows:
DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` ....
Delete Only Job Rows:
DELETE `job` FROM `deadline` LEFT JOIN `job` ....
By specifying the proper table in the DELETE statement, you can successfully remove the desired rows based on the status in the job description table.
The above is the detailed content of How to Delete Rows Using MySQL LEFT JOIN with DELETE Syntax?. For more information, please follow other related articles on the PHP Chinese website!