1

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.

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.