SQL Question
I wonder if I can write a single sql INSERT
statement to insert a row into a table where some of the fields come from variables and others come from another table. Currently I select from tableA
, store the fields in variables and then insert them into tableB
.
In the following example I'd like to get field1
, field2
, and field3
from tableA
and the rest from variables. (mysql)
$sql = "SELECT field1, field2, field3 FROM tableA where product = 5";
php code
$sql = "INSERT tableB
SET
fkey = 100,
custid = 10,
product = 5,
field1 = '$field1',
field2 = '$field2',
field3 = '$field3' ";