Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Select query inside insert query

 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this

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

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic