我需要在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'
任何帮助都将不胜感激。
答案 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 join
和left 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