I am trying to copy 1 table selected columns INTO 2nd table selected columns, using this:
$sql = "SELECT (p.col1, p.col2)
INTO tblColors(b1,b2)
FROM tblPuppies as p
WHERE p.col3=1
";
But its giving me error : Undefined variable tblColors. Strange to me. Any guesses plz, where m going wrong ?? Thanks tons in Advance.
Just use
INSERT INTO tblColors (b1, b2)
SELECT col1, col2 FROM tblPuppies WHERE b3 = 1
Try this
INSERT INTO destination_table (
Field_1,
Field_2,
Field_3)
SELECT Field_1,
Field_2,
Field_3
FROM source_table;
You are using the incorrect SQL for doing this. The syntax you used works for T-SQL (or MS-SQL). But you are working on MySQL which has different syntax. You have update the statement as follows:
$sql = "INSERT INTO tblColors (b1, b2)
SELECT p.col1, p.col2 FROM tblPuppies AS p WHERE b3 = 1";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.