Reputation: 599
I have a table named gen with structure like below; gen01 is the primary key
gen01 gen02 gen03
A 2 5
B 7 9
C 3 11
I want to copy a row and insert into the table. So I wrote a SQL
insert into gen (gen01, gen02, gen03)
values
(D, select gen02, gen03 from gen where gen01 = A)
and it report error "missing expression". What's the reason? Thx.
Upvotes: 1
Views: 4121
Reputation: 1
You can insert some row in same table on basic of condition..
INSERT INTO IMP_INVOICE_TAX (
SELECT * FROM IMP_INVOICE_TAX WHERE INVOICE_NO=1461009999)
Upvotes: 0
Reputation: 127
Try this
insert into gen (gen01, gen02, gen03)
select 'D', gen02, gen03
from gen where gen01 = 'A';
Upvotes: 4
Reputation: 1173
Please use below code.
CREATE TABLE gen(gen01 VARCHAR(100) PRIMARY KEY, gen02 INT, gen03 INT)
INSERT INTO gen(gen01,gen02,gen03)
VALUES('A',2,5),('C',3,11),('B',7,9)
insert into gen (gen01,gen02,gen03)
select 'D' as gen01,gen02,gen03 from gen where gen01='A';
select * from gen;
Upvotes: 0
Reputation: 15
you could try something like this
insert into your_table (c1, c2, ...)
select c1, c2, ...
from your_table
where id = 1
Upvotes: 0