Jump to content

Archived

This topic is now archived and is closed to further replies.

Buyocat

Inserting linked data into multiple tables at once

Recommended Posts

Hi I have two tables in a parent - child relationship and I'd like to be able to insert to them both with a single query.  If that isn't possible please just say so, if it is possible let me know!  Here are what my tables look like...

parent table
id
title
date_added
status

child table
parent_id
some_other_data

I want to be able to insert the data into the parent and then take the unique key id from that and place it into the child table along with any other data.  I can see how this can be done in two queries, however it seems like two queries is a lot, especially considering this is a frequently run insert.  So, is there any way to somehow get the inserted rows id from the parent table and push it into the child table all in one step?

Share this post


Link to post
Share on other sites
Can't do that... one insert per table, then just grab the LAST_INSERT_ID().

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.