1

只是试图让我的 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';
4

1 回答 1

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';
于 2013-03-05T15:52:47.573 回答