• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help with a SQL Insert Statement

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic