简体   繁体   中英

How to use select statement to insert values on a table

I am trying to insert theses values to my table student but I have an error

insert into student(first_name,last_name,student_number,professor_id)
  values(Eden,Yuan,323744573, 
  select professor_id from PROFESSORS where professor_name =  'Chu ')

I get an error

saying missing expression

you can use this way (assuming that professor_id is the column you need)

insert into student(first_name,last_name,student_number,professor_id) 
select 'Eden', 'Eden', 323744573, column_professor_id 
from PROFESSORS where professor_name = 'Chu ' ;

(In your query is missing the column in the select )

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM