1

I am using MS Access. I have written this query...

INSERT INTO survey1 ( [Coach No] )
SELECT pvc1.[Coach No]
FROM pvc1 LEFT JOIN survey1 ON pvc1.[Coach No]=survey1.[Coach No]
WHERE (((survey1.[Coach No]) Is Null));

BUT it is not appending data in my table survey1...

2
  • 1
    are you getting an error message? Commented Aug 2, 2011 at 17:49
  • while running query it is saying that it can't append due to KEY VIOLATIONS. But I am not able to figure out which key violations? Commented Aug 3, 2011 at 11:27

2 Answers 2

2

Break the query up. Does just the select return any results?

SELECT pvc1.[Coach No]
FROM pvc1 LEFT JOIN survey1 ON pvc1.[Coach No]=survey1.[Coach No]
WHERE (((survey1.[Coach No]) Is Null))
Sign up to request clarification or add additional context in comments.

Comments

1

Your query doesn't make sense. You are joining on NULL, then you try to insert that NULL into a table as a PK where it originally came from. You are joining with survey1 on Coach No and are trying to insert the Coach No back into survey1 What are you trying to do here?

Update now that OP elaborated on what he wants to do:

INSERT INTO survey1 ( [Coach No] )
SELECT pvc1.[Coach No]
FROM pvc1 
WHERE pvc1.[Coach No] NOT IN (SELECT [Coach No] FROM survey1 WHERE NOT [Coach No] IS NULL)

5 Comments

Actually I want to make a query to add [Coach No] from [pvc1] that are not in [survey1].
It is selecting those [Coach No] in datasheet view but do not append it when I run it. When it is run it gives error message like it can't append due to some KEY VIOLATIONS.
Ok, is this a foreign key tzo some other table?
[Coach No] is a primary key in both the tables [pvc1] and [survey1].
And it's not a foreign key to some other PK?

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.