2014-01-30 54 views
0

我有以下查詢,我不知道爲什麼我得到錯誤Syntax error in FROM clauseFROM子句中的MS Access語法錯誤

SELECT * 
FROM t_object 
INNER JOIN 
(
    SELECT * 
    FROM t_objectproperties tag 
    WHERE tag.Property = 'Location' 
    AND tag.Value = 'Queens' 
) AS location 
    ON t_object.Object_ID = location.Object_ID 
INNER JOIN 
(
    SELECT * 
    FROM t_objectproperties tag 
    WHERE tag.Property = 'Room' 
    AND tag.Value = 'King' 
) AS type 
    ON t_object.Object_ID = type.Object_ID 

回答

2

MS Access要求你用你的周圍多個括號聯接:

SELECT * 
FROM (t_object 
INNER JOIN 
(
    SELECT * 
    FROM t_objectproperties as tag 
    WHERE tag.Property = 'Location' 
    AND tag.Value = 'Queens' 
) AS location 
    ON t_object.Object_ID = location.Object_ID) 
INNER JOIN 
(
    SELECT * 
    FROM t_objectproperties as tag 
    WHERE tag.Property = 'Room' 
    AND tag.Value = 'King' 
) AS type 
    ON t_object.Object_ID = type.Object_ID 

這也可以寫成:

SELECT * 
FROM (t_object as o 
     INNER JOIN t_objectproperties as location 
     ON o.Object_ID = location.Object_ID) 
     INNER JOIN t_objectproperties as type 
     ON o.Object_ID = type.Object_ID 
WHERE location.Property = 'Location' 
    AND location.Value = 'Queens' 
    AND type.Property = 'Room' 
    AND type.Value = 'King' 
+0

感謝bluefeet。我嘗試過,但我仍然得到相同的錯誤。 – PeanutsMonkey

+0

謝謝bluefeet。現在,我收到錯誤'JOIN操作中的語法錯誤' – PeanutsMonkey

+0

不是'FROM t_objectproperties標籤'。而是'FROM t_objectproperties AS標籤'。這是一個Access的東西。 – Smandoli

相關問題