0

So I have a table called QUEUE with the columns STUDENT_ID, S_NAME, PASSWORD I want to write an SQL statement to copy the values within only the first 2 columns (i.e. STUDENT_ID, S_NAME) to another table STUDENT with columns STUDENT_ID, S_NAME only.

I tried this

insert into student (student_id, s_name) as (student_id, s_name) from queue

I'm new to SQL so I'm pretty sure this is incorrect. Can someone please help me out with this? Thanks. :)

1 Answers1

2

Use INSERT INTO .. SELECT FROM construct like

insert into student (student_id, s_name) 
select student_id, s_name from queue
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • 1
    Just a note and I know but if anyone would have same problem but into db with already existing rows go here: https://stackoverflow.com/questions/2763817/sql-update-fields-of-one-table-from-fields-of-another-one to Scott Bailey's answer. I myself got here first and this was not solution to my problem since it created new rows under existing ones. – eXPRESS Nov 19 '18 at 12:15