Solved

How to select max row per group in SQL

Posted on 2009-07-09
1
356 Views
Last Modified: 2012-05-07
Here is some sample data from the case_text table

company_id    case_id    text_type_code    case_text_seq
MIS                  1              Resolution             21
MIS                  1              Resolution             22
MIS                  2              Resolution             5
MIS                  2              Resolution             6
MIS                  2              Resolution             4

I am trying to create a query that will return the row with the highest case_text_seq value for a given combination of company_id,  case_id,  and  text_type_code    

Using the sample data above, I would like the query results to look like the following:

company_id    case_id    text_type_code    case_text_seq
MIS                  1              Resolution             22
MIS                  2              Resolution             6
0
Comment
Question by:johnnyg123
1 Comment
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24815434
SELECT company_id   , case_id  ,  text_type_code ,  MAX( case_text_seq)case_text_seq
from case_Table
GROUP BY  company_id   , case_id  ,  text_type_code
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question