View previous topic :: View next topic
|
Author |
Message |
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
I need to fetch record with recent updated timestamp. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Use this query
Code: |
select * from table where timestamp_col = (select max(timestamp_col)
from table );
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Rajesh,
do you need to know the last update for every 'ACCOUNT', or only the last updates, regardless of 'ACCOUNT'? |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@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 |
|
|
|