Insert with Where Statement Not Working (1 Viewer)

EzGoingKev

Registered User.
Local time
Yesterday, 21:57
Joined
Nov 8, 2019
Messages
35
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

Registered User.
Local time
Yesterday, 21:57
Joined
Apr 9, 2015
Messages
3,557
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
Local time
Yesterday, 18:57
Joined
Oct 29, 2018
Messages
10,258
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
Yesterday, 21:57
Joined
Nov 8, 2019
Messages
35
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 (Users: 0, Guests: 1)

Top Bottom