gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:05:56 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com