So, let's say I have a database of fruits, along with recipes based on those fruits.
id | fruit name |
---|---|
1 | apple |
2 | pear |
id | recipe | fruit_id |
---|---|---|
1 | apple pie | 1 |
2 | baked apple | 1 |
3 | poached pear | 2 |
Is it possible, using a single SQL insert in MySQL, to add a new fruit (banana) and 1 or more associated recipes ('bananas foster', 'banana bread')?
Thanks
insert
only inserts into one table at a time.LAST_INSERT_ID()
to get the ID that was assigned to the fruit.