If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Update a record with highest date

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-09, 17:30
Naweed Naweed is offline
Registered User
 
Join Date: Nov 2003
Posts: 76
Question Update a record with highest date

I am trying to select a record out of 40 with the highest date, to update. How should I do this.

col1 col2 col3 col3
ab1 xy2 lm3 date1
ab1 xy4 lm3 date1
ab1 xy5 lm3 date2 (higherst)
ab1 xy6 lm3 date1

I would like to selct the record for highest date2 and update lm3 to lm33.

How do I do this?
Reply With Quote
  #2 (permalink)  
Old 07-01-09, 20:31
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,151
Post DDL for table.
Post DML for test data.
Post expected/desired results (that matches test data).
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 07-02-09, 02:12
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,591
Something like
Code:
update your_table t1 set
  t1.col3 = lm33
where t1.col4 = (select max(t2.col4)
                 from your_table t2
                 where t2.col1 = t1.col1
                );
In other words: find the maximum COL4 date (possibly for every COL1 - thus the WHERE clause) and update this record's COL3 column to a new value.
Reply With Quote
  #4 (permalink)  
Old 07-09-09, 13:21
Naweed Naweed is offline
Registered User
 
Join Date: Nov 2003
Posts: 76
Thank you folks. I am sorry I wasnt able to respond sooner.
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On