Solved

How to select max row per group in SQL

Posted on 2009-07-09
1
362 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 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.

696 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