MS Access数据库中的SQL查询错误

时间:2014-10-15 21:34:47

标签: sql ms-access windows-7 ms-access-2010

我需要在MS Access中执行sql查询。

但我在MS Access中遇到错误:

SELECT * 
FROM 
(
   SELECT * 
   FROM table1
   where not exists 
   (
     SELECT *  
     FROM table2
     where table2.id = table1.id
   ) as t
 )  as t1, table3
 where  table3.id = t1.id

查询表达式中的语法错误:(缺少运算符)'不存在(...)为t'

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

not exists subselect不需要别名。请注意,我已删除as t

SELECT * 
FROM 
(
   SELECT * 
   FROM table1
   where not exists 
   (
     SELECT *  
     FROM table2
     where table2.id = table1.id
   ) 
 )  as t1, table3
 where  table3.id = t1.id

您也可以考虑使用inner joinleft join来摆脱not exists

这应完全等同于上述内容:

SELECT t1.*, t3.* 
FROM 
  table1 t1 
  inner join table3 t3 on t1.id = t3.id
  left join table2 t2 on t1.id = t2.id
where
  t2.id is null