• 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

Insert a new row with values from an existing record

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How can i add a new row with the values of an existing row..the only value that i will supply is the primary key..

I am not getting the sql query for that...

the database i am using is db2..

Is it possible with a single insert statement..What should i do?

Thanks in advance,


[ September 18, 2006: Message edited by: A Kumar ]
[ September 18, 2006: Message edited by: A Kumar ]
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe what you are looking for is called an INSERT SELECT statement. Although this can be DB specific the basic syntax is:
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks !!!

But what i want is ...

in the insert statement..i will provide the primary key value...and the rest of the columns from another row in the same table..

Regards
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a near solution

insert into table
select * from table2 where table2.id=?

But this one wont allow me to specify table.primarykey value explicitly

Regards
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by A Kumar:

But this one wont allow me to specify table.primarykey value explicitly



This will certainly allow you to do anything you want, you need to tweak a little bit, assuming TABLE1_ID is your primary key



Shailesh
 
reply
    Bookmark Topic Watch Topic
  • New Topic