File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Oracle/OAS and the fly likes Using Select query inside insert query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Reply Bookmark "Using Select query inside insert query" Watch "Using Select query inside insert query" New topic
Author

Using Select query inside insert query

Jose Mon
Ranch Hand

Joined: Feb 13, 2007
Posts: 30
Hi,

In an insert statement I want to insert some data from another table.
I used select query inside the insert query, but the database gives error.
I tried this in MySQL.

insert into t1(currency,price) values('USD',
select price from t2 where id='10'
)

Can anyone correct this query.

Thanks in advance..
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
In Oracle, I dont think you can use both value & a select statement in a insert query.
[ May 09, 2007: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

Try something like this

[CODE]
INSERT INTO t1(currency,price)
SELECT 'USD',
price
FROM t2
WHERE id='10'
[\CODE]

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Using Select query inside insert query
 
Threads others viewed
Oracle - insert auto_seq
Data base insert problem
Question on query - select one row with max value in one field
insert unique name into the table
how to improve performance
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture