SQL Access 中的多个 LEFT JOIN

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8581838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:42:12  来源:igfitidea点击:

Multiple LEFT JOIN in Access

sqlms-accesssql-deletejet

提问by grjj3

I have the following query, which works for MySQL:

我有以下查询,适用于 MySQL:

DELETE `test1`, `test2`, `test3`, `test4` FROM
`test1` LEFT JOIN `test2` ON test2.qid = test1.id
LEFT JOIN test3 ON test3.tid = test2.id
LEFT JOIN test4.qid = test1.id
WHERE test1.id = {0}

But it doesn't work for MS Access. I've tried to add parentheses around the LEFT JOIN, but it gives me syntax error in FROM clause. So how should this query look in order to work in MS Access?

但它不适用于 MS Access。我试图在 周围添加括号LEFT JOIN,但它在 FROM 子句中给了我语法错误。那么这个查询应该如何才能在 MS Access 中工作呢?

回答by Olivier Jacot-Descombes

The Access DELETE requires a star (*): DELETE * FROM ...

Access DELETE 需要星号 (*): DELETE * FROM ...

In addition, the joins must be nested by using parentheses:

此外,连接必须使用括号嵌套:

DELETE test1.*, test2.*, test3.*, test4.*
FROM
    (
      (
        test1 
        LEFT JOIN test2 ON test1.qid = test2.id
      )
      LEFT JOIN test3 ON test2.tid = test3.id
    )
    LEFT JOIN test4 ON test1.qid = test4.id
WHERE test1.id = {0}

回答by JeffO

Here is a sample select statement on three tables with left joins:

以下是对具有左连接的三个表的示例选择语句:

SELECT 
FROM (Table1 LEFT JOIN Table2 ON Table1.field1 = Table2.field2) 
LEFT JOIN Table3 ON Table2.field2 = Table3.field3;

Your deleted statement:

您删除的声明:

DELETE test1.*, test2.*, test3.*, test4.* 
FROM
((test1 LEFT JOIN test2 ON test2.qid = test1.id)
LEFT JOIN test3 ON test3.tid = test2.id)
LEFT JOIN test4.qid = test1.id)
WHERE (((test1.id) = [SomeParameter]));