I want to transfer data from one table to another and also i want add an additional column in second table.
INSERT INTO invoiceitem(invoiceno, barcode, itemname, quantity, unitprice, subamount)
VALUES
('$Succ2', SELECT barcode, resultname, quantity, resultprice, subamount)
FROM test;
If you want to insert using the result set of a query, the syntax is INSERT INTO ... SELECT
, ie we do not use VALUES
in this case. It is possible to add a literal value to a SELECT
statement, eg try this:
INSERT INTO invoiceitem (invoiceno, barcode, itemname, quantity, unitprice, subamount)
SELECT '$Succ2', barcode, resultname, quantity, resultprice, subamount
FROM test;
The right syntax is:
INSERT INTO invoiceitem(invoiceno,barcode,itemname,quantity,unitprice,subamount)
SELECT '$Succ2' ,barcode,resultname,quantity,resultprice,subamount FROM test;
If you want to insert values from one table to another, need not use VALUES in insert query. pls refer INSERT TABLE TO ANOTHER TABLE
INSERT INTO invoiceitem (invoiceno, barcode, itemname, quantity, unitprice, subamount)
SELECT '$Succ2' barcode, resultname, quantity, resultprice, subamount
FROM test;
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.