sql code

Can you tell what's wrong with the query:

SELECT First([THREE-OR-MORE-MRTG].[T-Loan-No]) AS FirstLoan, First([THREE-OR-MORE-MRTG].[MRTG-NO]) AS GrpNumber
FROM [THREE-OR-MORE-MRTG]
GROUP BY [THREE-OR-MORE-MRTG].[T-DSC-USE], [THREE-OR-MORE-MRTG].[MRTG-NO];

I have following data

T-Loan-No                          MRTG-NO
250821                                 25
250834                                 25
250847                                 25
270157                                  25
271127                                  25
271130                                  25

anytime, i'm trying to pickup last loan in this group it picks 270157 instead of 271130 which I do need
maximyshkaAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
that's because of FIRST() function... use MAX(), or LAST() instead:
SELECT MAX([T-Loan-No]) AS max_t_loan
, LAST([T-Loan-No]) as last_t_load
, FIRST([T-Loan-No]) as first_t_load
, [MRTG-NO] AS GrpNumber
FROM [THREE-OR-MORE-MRTG]
GROUP BY [MRTG-NO];

Open in new window

0
 
maximyshkaAuthor Commented:
Thanks, but why Last Not working.  Max, is good
0
All Courses

From novice to tech pro — start learning today.