FROM子句中的MS Access语法错误

时间:2014-01-30 18:54:08

标签: ms-access

我有以下查询,我不知道为什么会收到错误Syntax error in FROM clause

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 

1 个答案:

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