Access中有多个LEFT JOIN

问题描述 投票:4回答:2

我有以下查询,适用于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}

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

sql ms-access sql-delete jet
2个回答
12
投票

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

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

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}

2
投票

以下是带有左连接的三个表的示例select语句:

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

你删除的声明:

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]));
© www.soinside.com 2019 - 2024. All rights reserved.