File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Oracle/OAS and the fly likes Using Select query inside insert query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Using Select query inside insert query" Watch "Using Select query inside insert query" New topic

Using Select query inside insert query

Jose Mon
Ranch Hand

Joined: Feb 13, 2007
Posts: 30

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

Joined: Feb 05, 2001
Posts: 17276

Try something like this

INSERT INTO t1(currency,price)
WHERE id='10'


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Using Select query inside insert query
It's not a secret anymore!