使用 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 删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)