sql - MySQL,删除带有连接的查询

标签 sql mysql

谁能帮我理解这个查询有什么问题:

DELETE FROM noteproject 
INNER JOIN note ON noteproject.noteID = note.noteID
INNER JOIN person ON note.personID = person.personID
WHERE noteID = '#attributes.noteID#' 
  AND personID = '#attributes.personID#'

最佳答案

目前我没有数据库来测试我在说什么,但是here's a reference to the mysql docs以您的案例为例:

You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the particular condition in the WHERE clause.

还有:

1) For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted.
2)For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted.
The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching:

1)
DELETE t1, t2 
FROM t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;

2)
DELETE FROM t1, t2 
USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;

These statements use all three tables when searching for rows to delete, but delete matching rows only from tables t1 and t2.

关于sql - MySQL,删除带有连接的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1962185/

相关文章:

mysql - 从特定数据库中检索所有表名、列名和列值

mysql - Perl 代码始终连接到同一个 MySQL 数据库,尽管它被配置为连接到不同的服务器

php - 提高php的速度

php - 将面向对象的数据直接编码为关系数据库中的单行是否被认为是错误的形式?

java - 如何使用 Hibernate 进行查询并对对象字段应用限制

sql - 在 PostgreSQL 中创建函数时出现问题 "ERROR: syntax error at or near "ROWTYPE""

如果没有找到最接近的最小值,Mysql : find nearest Maximum value,

php - 我可以预测我的 Zend Framework 索引有多大吗? (和一些快速 Q :s)

mysql - 删除所有超过 15 分钟的条目

mysql - SQL HAVING 子句中的算术运算符