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. :)

2
  • 1
    Why did you tag this with every database you can think of? Which one are you actually using? Commented Nov 1, 2016 at 19:02
  • Using postgresql sorry. fixed it Commented Nov 1, 2016 at 19:03

1 Answer 1

2

Use INSERT INTO .. SELECT FROM construct like

insert into student (student_id, s_name) 
select student_id, s_name from queue
Sign up to request clarification or add additional context in comments.

1 Comment

Just a note and I know but if anyone would have same problem but into db with already existing rows go here: stackoverflow.com/questions/2763817/… 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.