简体   繁体   中英

error of sql query in MS Access database

I need to do a sql query in MS Access.

But I got error in 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

Syntax error: (missing operator) in query expression 'not exists ( ... ) as t'

Any help would be appreciated.

The not exists subselect does not require an alias. Note that I've removed the 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

You might also consider using an inner join and a left join to get rid of your not exists :

This should be exactly equivalent of the above:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM