This might be hard to understand so let me know if I need to describe it better. Say I have 3 tables tableA, tableB, and tableC with the following syntax:
CREATE TABLE tableA (
data_point_1 VARCHAR(30),
data_point_2 VARCHAR(30),
data_point_3 VARCHAR(30)
);
CREATE TABLE tableB (
bid INTEGER AUTO_INCREMENT,
cid INTEGER AUTO_INCREMENT,
data_point_1 VARCHAR(30),
);
CREATE TABLE tableC (
cid INTEGER AUTO_INCREMENT,
data_point_2 VARCHAR(30),
data_point_3 VARCHAR(30)
);
Now what I want to do is transfer the data from tableA into tableB and tableC. So in essence I want something like:
INSERT INTO tableB
SELECT
data_point_1,
(SELECT cid FROM tableC WHERE (INSERT INTO tableC SELECT data_point_2, data_point_3 FROM tableA))
FROM tableA
I haven’t tried the above, but I’m assuming it is not possible since INSERT doesn’t return the actual values (I would need a select I assume), but my question becomes how can I insert data from A put it into C and then at the same time grab the id from C and another data point from A and place those both into B.
I figure I can probably break it up into 2 insert statements and then do a select on C where data_point_2 = data_point_2 and data_point_3=data_point_3, but I was wondering if there was a way to do it in just one query? I couldn’t find anything so I figured I’d ask here.
Again: I don’t want 2 separate insert queries. I want to be able to do it in 1. (Cause theoretically I might need to abstract it further)
The solution looks to be that there is no solution =/ guess i’ll have to do it in multiple inserts. Thanks for all the help everyone.