• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help with a SQL Insert Statement

 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me try to describe my situation. I have two tables, I'll call them src and dest, and I'd like to take some data from the src table and insert it into the dest table. For every row in the src table, I need to create a new row in the dest table (by an INSERT statement, I presume) and copy all of the data from that table to this table. I'd like to do something like this:



Obviously, that doesn't work, but hopefully it gives you an idea of what I'm trying to accomplish. Unfortunately, I'm not very fluent in SQL and I just don't know how to construct a statement to accomplish this.

Any suggestions are greatly appreciated.

Thanks,
Corey
 
dhana rangu
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

INSERT INTO dest (ID, V1, V2) VALUES (SELECT ID, V1,V2 from SRC);
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget it - I couldn't figure out the SQL so I just wrote a quick JDBC app to do it for me. I guess I'm just not meant to be a DBA.
 
Ivor Lithan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably of no use to you now, but incase you were interested :

INSERT INTO dest (ID, V1, V2)
(SELECT ID, V1,V2 from SRC);

was what you wanted - the VALUE keyword isn't needed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic