John Higgins
John Higgins

Reputation: 907

Inserting data using a select

I am trying to do the following:

INSERT INTO job_additions (sor_no, sor_desc, invoice_no, qty, debit_credit)
VALUES
('CAR102008',(select sor_desc from sor_data where sor_no= CAR102008),'INV001002','2','d')

But I am getting an error of Unknown column 'sor_desc' in 'field list'

Is it possible to insert data that has been selected from another table?

Many thanks,

John

Upvotes: 1

Views: 30

Answers (1)

Filipe Silva
Filipe Silva

Reputation: 21657

Try it like this:

insert into job_additions (sor_no, sor_desc, invoice_no, qty, debit_credit)
select 'CAR102008', sor_desc, 'INV001002','2','d'
from sor_data 
where sor_no= 'CAR102008'

Upvotes: 1

Related Questions