insert on join

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This has got to be easy, but I couldn't find an existing post about it.

I've got two tables, each with an ID field that is used to perform an inner
join. I want to select all fields from each table. The primary table's ID
field is an autoincrement field, the other table's ID field is a Long.

How can I perform the select and then use the resulting recordset to insert
a new record and have the ID fields match? (I'm writing C++ code to do
this, but I just need the query syntax).

Thanks.
 
Select table1.*, table2.* from table1 inner join table2 on table1.id =
table2.id

An Autonumber is just a self-incrementing Long Integer.
 
Ignore last post, I missed something in the final paragraph.

The answer is: You can't update the child record with the ParentID, because
you don't know it yet. Instead, use ADO to insert a record into the parent,
then use that ID in the INSERT INTO for the child.
 
Yes, but once I have that recordset I need to insert a record and have the
'table2.id' set to the value of the self-incrementing 'table1.id'. Can that
be done during the insert?

Thanks
 
I thought that might be the answer... I guess it's not a one-step procedure.

Thanks for the help.
 
Back
Top