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 | 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
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: 17249
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Select query inside insert query
 
Similar Threads
insert unique name into the table
how to improve performance
Oracle - insert auto_seq
Question on query - select one row with max value in one field
Data base insert problem