Insert with Where Statement Not Working

EzGoingKev

Registered User.
Local time
Today, 15:37
Joined
Nov 8, 2019
Messages
199
I am using the following statement:

INSERT INTO table1 SELECT * FROM query2 WHERE 'table1.ID'<>'query2.ID'

There is already data in table1. I want to it to insert data to the table only where there already is not data listed using that ID

The macro runs but it just inserts everything from query2 into table1. It ignores the WHERE 'table1.ID'<>'query2.ID'.

What am I doing wrong?
 
Last edited:
build sql using the query design. It wont get it wrong. In fact, just use queries. There's not a big need to write sql.
but I think you used quotes.
fields don't need quotes, only strings you create as litterals.

iNSERT INTO table1 SELECT * FROM query2 WHERE table1.ID<>query2.ID
 
Hi. You could try something like:


Code:
INSERT INTO table1 SELECT * FROM query2 WHERE ID Not In(SELECT ID FROM table1)
 
build sql using the query design. It wont get it wrong. In fact, just use queries. There's not a big need to write sql.
but I think you used quotes.
fields don't need quotes, only strings you create as litterals.

iNSERT INTO table1 SELECT * FROM query2 WHERE table1.ID<>query2.ID
If I try to run it without the quotes I get the following error:

Syntax error in query expression 'table1.id<>query2.id'

Initially I tried brackets but they gave me an error also.
 

Users who are viewing this thread

Back
Top Bottom