Question

is it possible to insert values into different tables using mysql qyery??

No correct solution

OTHER TIPS

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

  1. your subsequent insert values can be derived from the value of the preceding insert
  2. 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.)

The 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow