How can I INSERT values to two tables using only one query? I am using MySQL. One of the tables I want to insert to is a many-to-many relationship table. Please see my example below:
I recently added the many-to-many relationship tables. When I insert on the news, I type the following script:
INSERT INTO news (title, reporter_id)
VALUES ('Some Title', 15);
How can I have one query an be able to insert to two tables? Per MySQL insert documentation, seems like I can do query like
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
The problem is, I dont know my news_id until I execute my first insert. Should I just have two insert statements or is there a better way? Thanks for your help!