See attached.
Main Topics
Browse All TopicsI have the following sql which returns 4 rows, i want to filter it further so that i only display the rows where the timestamp column OTR_TSP_REC_UPDATE is the most recent :
select OTR_RID_OST_TRAN,
OTR_CDE_GROUP_TYPE,
OTR_CDE_OBJ_STATE,
OTS_CID_LENDER,
OTR_AMT_ACTUAL,
OTS_AMT_BOOKING
OTR_TSP_REC_UPDATE,
OTR_DTE_EFFECTIVE
from vls_outstanding
left join vls_ost_tran on OTR_RID_OUTSTANDNG = OST_RID_OUTSTANDNG
join VLS_OST_TR_SG_SHR on OTR_RID_OST_TRAN = OTS_RID_OST_TRAN
where OST_NME_ALIAS = 'BURDON SPO00079'
and OTR_CDE_OBJ_STATE in ('PEND','AWSTA','AWREL' )
and OTR_CDE_GROUP_TYPE in ( 'QLR','LRP')
how should i ammend my code?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Putting MAX() in the SELECT clause will give you the max value for each grouping. For example, if your table is like:
myColor, myVal
Red, 1
Red, 1
Red, 2
Green, 1
Green, 2,
Green, 3
Green, 3
Blue, 2
Blue, 2
Blue, 2
Blue, 3
Blue, 3
Putting MAX(myVal) in the SELECT clause will give you one record for each group:
Red, 2
Green, 3
Blue, 3
If you want all records where myVal = MAX(myVal), then you will have to put that condition in the WHERE clause.
Or the analytic version (you have to add whatever fields you need to group by in the "partition by" clause)
select OTR_RID_OST_TRAN,
OTR_CDE_GROUP_TYPE,
OTR_CDE_OBJ_STATE,
OTS_CID_LENDER,
OTR_AMT_ACTUAL,
OTS_AMT_BOOKING
OTR_TSP_REC_UPDATE,
OTR_DTE_EFFECTIVE
from
(
select OTR_RID_OST_TRAN,
OTR_CDE_GROUP_TYPE,
OTR_CDE_OBJ_STATE,
OTS_CID_LENDER,
OTR_AMT_ACTUAL,
OTS_AMT_BOOKING
OTR_TSP_REC_UPDATE,
OTR_DTE_EFFECTIVE,
row_number() over (partition by ..... order by OTR_TSP_REC_UPDATE desc) rn
from vls_outstanding
left join vls_ost_tran on OTR_RID_OUTSTANDNG = OST_RID_OUTSTANDNG
join VLS_OST_TR_SG_SHR on OTR_RID_OST_TRAN = OTS_RID_OST_TRAN
where OST_NME_ALIAS = 'BURDON SPO00079'
and OTR_CDE_OBJ_STATE in ('PEND','AWSTA','AWREL' )
and OTR_CDE_GROUP_TYPE in ( 'QLR','LRP')
)
where rn=1
I think there has been a mistake as the accepted solution appears to me to be the wrong answer. Please read my response to that post above.
The OP says: "display the rows where the timestamp column OTR_TSP_REC_UPDATE is the most recent"
The OP wants only rows that have a timestamp equal to the the max value of OTR_TSP_REC_UPDATE. Not the max value of OTR_TSP_REC_UPDATE for each group.
A bit late? I only recieved the notification that the question was classified as abandoned this morning. Maybe four days is not enough time.
As for the missing group by clause. The OP is not asking for any grouping. The question says he/she wants to, "filter it further so that i only display the rows where the timestamp column OTR_TSP_REC_UPDATE is the most recent". The key word being "filter". There is no group by clause in the orignal post and none is needed. The OP wants to see ALL rows with timestamp equal to the latest value. Hence, it is a matter of adding another condition to the WHERE clause. Please reread the question.
Business Accounts
Answer for Membership
by: adlink_laPosted on 2008-08-22 at 19:59:47ID: 22295546
I think this should give you what you want...
Select allOpen in new window