Append only new records

B

bhammer

This must be simple, but . . .

INSERT INTO tblComponents.Component
SELECT Component
FROM tblComponentsDefault
WHERE tblComponentsDefault.Component <> tblComponents.Component;

I get an enter parameter dialog.

I simply have a default list of components in one, unrelated table
that the user can choose to append to the "real" components table (the
one with relationships to other tables), if they choose to. The user
may have no entries, or many entries in tblComponents, so I simply
want to add from the default list and avoid duplicates. The ID does
not come into play here, so . . . ?
 
K

KARL DEWEY

Try this --
INSERT INTO tblComponents.Component
SELECT Component
FROM tblComponentsDefault LEFT JOIN tblComponents ON
tblComponentsDefault.Component = tblComponents.Component
WHERE tblComponents.Component IS NULL;
 
M

MGFoster

bhammer said:
This must be simple, but . . .

INSERT INTO tblComponents.Component
SELECT Component
FROM tblComponentsDefault
WHERE tblComponentsDefault.Component <> tblComponents.Component;

I get an enter parameter dialog.

I simply have a default list of components in one, unrelated table
that the user can choose to append to the "real" components table (the
one with relationships to other tables), if they choose to. The user
may have no entries, or many entries in tblComponents, so I simply
want to add from the default list and avoid duplicates. The ID does
not come into play here, so . . . ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

First off your syntax is incorrect on the INSERT clause - you need to
put the column name in parentheses. You also have to LEFT JOIN the 2
tables together to get what you want:

INSERT INTO tblComponents (Component)
SELECT D.Component
FROM tblComponentsDefault AS D LEFT JOIN tblComponents As C ON
D.Component=C.Component
WHERE C.Component IS NULL

This translates to: Insert the Component into tblComponents from
tblComponentsDefault where there is a component in tblComponentsDefault
but not in tblComponents (C.Component IS NULL).

This all assumes that there is only one column in tblComponents (or 2
columns, one being an AutoNumber column).
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSXjsC4echKqOuFEgEQLcoACg1aAYCjPo6C+0f36hMktA0Sp1engAn1yr
dvmJ+tG6kBpKco0xGb6vESeJ
=JiDQ
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top