Home > Database > Mysql Tutorial > How to Delete Rows Using MySQL LEFT JOIN with DELETE Syntax?

How to Delete Rows Using MySQL LEFT JOIN with DELETE Syntax?

DDD
Release: 2024-12-01 19:49:10
Original
945 people have browsed it

How to Delete Rows Using MySQL LEFT JOIN with DELETE Syntax?

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'
Copy after login

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` ....
Copy after login

Delete Both Deadline and Job Rows:

DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` ....
Copy after login

Delete Only Job Rows:

DELETE `job` FROM `deadline` LEFT JOIN `job` ....
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template