Insert with Where Statement Not Working (1 Viewer)

EzGoingKev

Registered User.
Local time
Today, 13:57
Joined
Nov 8, 2019
Messages
178
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:

Ranman256

Well-known member
Local time
Today, 13:57
Joined
Apr 9, 2015
Messages
4,339
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:57
Joined
Oct 29, 2018
Messages
21,358
Hi. You could try something like:


Code:
INSERT INTO table1 SELECT * FROM query2 WHERE ID Not In(SELECT ID FROM table1)
 

EzGoingKev

Registered User.
Local time
Today, 13:57
Joined
Nov 8, 2019
Messages
178
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

Top Bottom