?
Solved

How to select max row per group in SQL

Posted on 2009-07-09
1
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

741 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