2011-12-20 83 views
2

我有以下查詢,其工作原理爲MySQL:多LEFT JOIN在Access

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訪問工作。我試圖在LEFT JOIN附近添加圓括號,但它在FROM子句中給我提供了語法錯誤。 那麼這個查詢應該如何看待才能在MS Access中工作?

回答

9

的訪問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} 
+0

儘管我懷疑{0} :) – Fionnuala 2011-12-20 21:22:13

+0

噢,謝謝,我看到我錯過了上次連接中的'test4 ON'部分。 – grjj3 2011-12-20 21:23:46

+0

也許他想用'String.Format(sql,some_id);'替換它,如果他使用的是C#或VB.NET。 – 2011-12-20 21:25:31

1

下面是三個表的樣本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]));