Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max Row from a group 1

Status
Not open for further replies.

IAMINFO

MIS
Feb 21, 2002
62
US
Hello everyone,
The following sql

Select Severity,Offender,Descr
from chargeview
where offender = 16744 and eclock is null

produces the following result set

severity offender descr
99300 16744 vop
14200 16744 agg asslt
99904 16744 187
53232 16744 bw

I need the result set to only show the row with the highest severity level. I am not sure how to write the subquery if one is needed , any guidance or assistance would be most appreciated.
Thank you for taking the time to read this post and helping.


 
Code:
Select Severity,Offender,Descr
from chargeview
INNER JOIN (SELECT MAX(Severity) AS Severity
                   from chargeview
            where offender = 16744 and eclock is null) Tbl1
ON chargeview.Severity = Tbl1.Severity
where chargeview.offender = 16744 and 
      chargeview.eclock is null

If you use 2005 or 2008 you could use ROW_NUMBER() OVER (...).


Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
bborissov's thank you so very much , the code worked perfectly
I had researched the issue with no luck, again thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top