使用 MySQL LEFT JOIN 删除行

Deleting rows with MySQL LEFT JOIN(使用 MySQL LEFT JOIN 删除行)
本文介绍了使用 MySQL LEFT JOIN 删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张表,一张用于工作截止日期,一张用于描述工作.每个作业都可以有一个状态,有些状态意味着必须从另一个表中删除作业的截止日期.

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.

我可以使用LEFT JOIN轻松SELECT满足我的条件的工作/截止日期:

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属于job表而不是deadline)

但是当我想从 deadline 中删除这些行时,MySQL 会抛出错误.我的查询是:

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 错误什么也没说:

MySQL error says nothing:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'LEFT JOIN job ON Deadline.job_id = job.job_id WHERE status = 'szaml' 附近使用的正确语法第 1 行

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

如何将我的 SELECT 转换为有效的 DELETE 查询?

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

推荐答案

您只需指定要在哪些表上应用 DELETE.

You simply need to specify on which tables to apply the DELETE.

仅删除 deadline 行:

DELETE `deadline` FROM `deadline` LEFT JOIN `job` ....

删除deadlinejob行:

DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` ....

仅删除 job 行:

DELETE `job` FROM `deadline` LEFT JOIN `job` ....

这篇关于使用 MySQL LEFT JOIN 删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)