Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 14th, 2005, 06:36 AM
suresh1977 suresh1977 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 suresh1977 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 16 m 57 sec
Reputation Power: 0
Update Statement Between Two Tables

Hi,

I have a table with the Following fields City, Txns in the table BOB_BK. There is another table "SUM_MONTH" with the same two fields with some additional information. Now I want to get Value in the field TXNS of BOB_BK in "SUM_MONTH" Table. But when i write the following query

UPDATE SUM_MONTH A
SET A.TXNS = B.TXNS FROM BOB_BK B, SUM_MONTH A
WHERE A.CITY = B.CITY... It gives me a error saying SQL not complete. Then I Tried the following query

UPDATE SUM_MONTH A
SET A.TXNS = (SELECT B.TXNS FROM
BOB_BK B, SUM_MONTH A
WHERE B.CITY = A.CITY).. It gives an error saying subquery returning more than one value. but if i remove the = sign and replace it by IN it still gives as error saying "= sign missing". So how do i run this update???

Thanks in Advance
Suresh

Reply With Quote
  #2  
Old January 14th, 2005, 08:46 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Code:
UPDATE SUM_MONTH A
SET A.TXNS = (SELECT b.TXNS FROM
BOB_BK B
WHERE B.CITY = A.CITY)
where city in (select city from bob_bk)

Reply With Quote
  #3  
Old January 15th, 2005, 04:25 AM
suresh1977 suresh1977 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 suresh1977 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 16 m 57 sec
Reputation Power: 0
THis is not working.Still gives me an error ORA-01427: single-row subquery returns more than one row.

The latest Query...
UPDATE SUM_MONTH A
SET A.TXN_COUNT_M = (SELECT b.TRNS
FROM BOB_BK B
WHERE A.N_CITY_CODE = B.N_CITY_CODE
AND A.BANK_CODE = '00001')
WHERE N_CITY_CODE in (select N_CITY_CODE from bob_bk);

Can you suggest something else...

Reply With Quote
  #4  
Old January 16th, 2005, 10:15 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
So, for some cities in the SUM_MONTH tables there are multiple records in the BOB_BK table. Which of those rows shall you choose? Or should you do an aggregation instead? It's your choice.

Reply With Quote
  #5  
Old January 17th, 2005, 07:52 AM
suresh1977 suresh1977 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 suresh1977 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 16 m 57 sec
Reputation Power: 0
Obviously I had to use the aggregate function. and it worked. Thanks a lot for your help buddy... Helped me restore the data in the production server. Thanks a million again.....

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Update Statement Between Two Tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway