将SQL查询转换为MS-Access SQL

时间:2013-03-05 15:46:49

标签: sql ms-access

只是尝试让我的SQL查询在MS-Access中工作,但它不想这样做。我试图找到一个指南或类似的东西,因为我知道它发生了很多时间,它通常只是添加一些括号,但我无法让这个查询工作,尽管我尝试了所有:

SELECT t1.Name AS lev1, t2.Name as lev2, t3.Name as lev3, t4.Name as lev4
FROM Folder AS t1
LEFT JOIN Folder AS t2 ON t2.Parent = t1.ObjId 
LEFT JOIN Folder AS t3 ON t3.Parent = t2.ObjId 
LEFT JOIN Folder AS t4 ON t4.Parent = t3.ObjId 
WHERE t1.ObjId = '123456789';

1 个答案:

答案 0 :(得分:4)

MS Access需要围绕每个联接使用括号。当你有多表连接时,你将有几个:

SELECT t1.Name AS lev1, t2.Name as lev2, t3.Name as lev3, t4.Name as lev4
FROM ((Folder AS t1
LEFT JOIN Folder AS t2 ON t2.Parent = t1.ObjId)
LEFT JOIN Folder AS t3 ON t3.Parent = t2.ObjId)
LEFT JOIN Folder AS t4 ON t4.Parent = t3.ObjId 
WHERE t1.ObjId = '123456789';

格式化它看起来像这样:

SELECT t1.Name AS lev1, t2.Name as lev2, t3.Name as lev3, t4.Name as lev4
FROM 
(
    (
        Folder AS t1
        LEFT JOIN Folder AS t2 ON t2.Parent = t1.ObjId
    )
    LEFT JOIN Folder AS t3 ON t3.Parent = t2.ObjId
)
LEFT JOIN Folder AS t4 ON t4.Parent = t3.ObjId 
WHERE t1.ObjId = '123456789';