INSERT INTO (JOIN)

  • Thread starter Thread starter Glenn
  • Start date Start date
G

Glenn

This statement works for me:

INSERT INTO Customers ( LastName, FirstName, CardID,
CardStatus, Notes )
VALUES
('LastName', 'FirstName', 'CardID', 'CardStatus', 'Notes')
;

The VALUES are passed by an external database front-end
program.

How do I then add VALUES ('Address', 'City','State') to
table Customers_Address whereby there is a "INNER JOIN
Customers_Address ON Customers.UniqueID =
Customers_Address.CustomerID" ?? With VALUES again passed
by the front-end app, and hopefully via the same SQL
query.
 
Hi,

If at least one column is in a table, use an INSERT INTO ... SELECT :


INSERT INTO myTable(f1, f2) SELECT column1, 666 FROM somewhere



Hoping it may help,
Vanderghast, Access MVP
 
Michel,

Thank you for your reply. However I don't think your
solution is the one I am looking for. I may not have
described the scenario correctly. I have two tables;
Customers and Customer_Address. The tables are in a one
to many relationship; Customers.CustomerID(PK) and
Customer_Address.Customer(FK). Say for example, I have a
*.csv file containing new customer name etc details to be
inserted into Customers table and details of that
customer's address to be inserted into Customer_Address
table. I understand I can JOIN two INSERT statements but
I don't know the syntax. Any clearer??

Thanks again

Glenn
 
Hi,


Just one INSERT, it is the SELECT that gets the JOIN. Build the
SELECT with the join, retrieving all the fields, adding constant if you
want:

SELECT list_of_fields_or_expressions
FROM Customers As a INNER JOIN Address As b
ON a.ClientID=b.ClientID

then, prefix the beauty with " INSERT INTO tablename( listOfFields ) "


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top