Access中有多个LEFT JOIN

时间:2011-12-20 20:54:16

标签: sql ms-access sql-delete jet

我有以下查询,适用于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中工作?

2 个答案:

答案 0 :(得分: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}

答案 1 :(得分: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]));