Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Insert a new row with values from an existing record

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • 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: 4173
29
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic