inserting values into more than two table using one query
No correct solution
Yes, but you need to create custom functions that insert values to other tables as a side-effect.
The basic idea is that you want to insert the result of the function into the table you are inserting other data
insert into table (resulting_value) values (my_function(parameters))
You can read more about stored functions from the MySQL documentation
There is no one query that can do that, but assuming you're working with PHP, you can get the primary key of the last inserted row using
mysql_insert_id() and then you can construct the second query with that field.
you could maybe do it using a trigger(s) (i.e. you issue one SQL insert statement and subsequent inserts are carried out in the database), as long as
- your subsequent insert values can be derived from the value of the preceding insert
- you don't mind living with the problems that such an approach might give rise to (unclear error messages when a trigger fails, silent insert failures, performance issues etc.etc.)
Insert command just allows one target table for data to be inserted...
INSERT INTO target_table () VALUES();
A good workaround can be done while using Triggers.