IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To Fetch record with recent timestamp


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Wed Jun 18, 2008 4:40 pm
Reply with quote

I need to fetch record with recent updated timestamp.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 4:46 pm
Reply with quote

IS it you want to fetch the records with the latest timestamp ???
use a max on your timestamp col ... if not pls provide example of wht you want to achieve ..
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Wed Jun 18, 2008 5:07 pm
Reply with quote

Thanks ashimer for your reply,my question is ,i need to pick the record with recently updated timestamp not with current timestamp table

Ex:
In table ,records will be updated every day,but i need to pick record which is updated last,it may be updated yesterday.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 5:13 pm
Reply with quote

Use this query

Code:


select * from table where timestamp_col = (select max(timestamp_col)
from table );

Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 18, 2008 5:17 pm
Reply with quote

Rajesh,

do you need to know the last update for every 'ACCOUNT', or only the last updates, regardless of 'ACCOUNT'?
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Jun 18, 2008 5:18 pm
Reply with quote

Hi !

I think ashimer's proposal is just .
Otherwise use something like the following. First fetch is your result.

Declare Cursor
Where Update_TS <= Current_Timestamp
OrderBy TUpdate_TS
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 18, 2008 5:53 pm
Reply with quote

That's slick UmeySan. That cursor will pick up every row in the table.

And Ashimer's post will not work as imbedded sql.

the OP has not adequately described his requirements.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 18, 2008 6:05 pm
Reply with quote

The query which i have mentioned above will give the last updated record (as per the OP's req) ... now if its the requirement is for the last updated record for an "ACCOUNT" then this should work

Code:


select * from (select account,max(timestamp_col) from
table group by account) as temp;



PS: When the given requirement is not clear the OP will have to play with the hint given ...
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Jun 18, 2008 7:11 pm
Reply with quote

@Dick:

Right, slicky but working. From the first question, not really the details have been clear. So i have to agree to ashimer once more.

And seriously i agree with you.

Finally we're all brothers in arms, struggling against the daily pitfalls of our job.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts To get the count of rows for every 1 ... DB2 3
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top