top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I insert data into a table from two other tables in mysql?

0 votes
469 views

How can I insert data into one table from two other tables where i have three tables namely users, role and userrole.
Now I want to insert the data into userrole table from users table and role table with a single statement.

posted May 2, 2017 by Arunagames1 Dec

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Your question is not complete so answering based on the information what we have -

You need to use
INSERT INTO ...SELECT statement for insertion in the table 3.

Something like

INSERT INTO userrole (column1, column2, column3)
SELECT user.column1, user.column2, role.column3
FROM user, role
WHERE user.column1 = role.column1;
answer May 2, 2017 by Salil Agrawal
Similar Questions
+5 votes

How can I insert the content of excel file into MySQL Table, any pointer?

+2 votes

How I 'll check how many rows inserted into every second on an average in a table of MySQL database?

0 votes
for($i=0;$i<=feof($getdata);$i++)
{
if (filter_var($data[$i][1], FILTER_VALIDATE_EMAIL)){
echo $data[$i][1];
$email=$data[$i][1];
$conn = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO promo_user (uid,name,email) VALUES (,'', '$email')";
mysqli_query($sql,$conn);
mysqli_close($conn);

I am using the above code but there is something wrong with it,whenever i run the code the echo is working fine but the content does go into sql table

Please help

...