I have three datatables, tableA, tableB, and tableAB. The contents aren't really important, just that tableA and tableB have primary keys and tableABrelates the keys in the two tables. The basic structure is below:
aId|data ---+---- 1 |4 2 |83 bId|data ---+---- 1 |a 2 |cd 3 |bf abId|aId|bId ----+---+--- 1 |1 |1 2 |1 |2 3 |2 |3 What I'd like to do is combine the inserts of all three of these tables into one query, but am not sure how to. The current idea that I'm working with is below, but it does not work. Important things to note are aId's may refer to multiple bId's, but each bId will only have one aId referring to it. As such, aId's may not refer to existing bId's. The big things I am struggling with are 1) making the value of an insert come from another insert, and 2) simulating multiple inserts, for bId's, in a single query.
Current query:
insert into tableAB(aId, bId) values((select aId from(insert into tableA(data) values(5))), (select bId from(insert into tableB(data) values("f")))); I'm really not sure multiple inserts in a single query is possible and don't know a way of writing it above.
INSERTqueries don't return a value, you can't use them as subqueries in aSELECT.