Solved

Use of MAX, GROUP BY

Posted on 2007-03-27
5
4,584 Views
Last Modified: 2010-04-27
Hi,
I've a query that returns me 3 data:

select number, name, editor
from table

I'd like to have the max(number),name, editor for each editor.
Exemple: the table:
result     name      editor
50          toto         A
60          dada       A
20          toto         B
10          dada       B

I want the follwoing result:
result     name    editor
60          dada     A
20          toto       B

Thanks & Regards.


0
Comment
Question by:bruno_boccara
5 Comments
 
LVL 11

Expert Comment

by:Ved Prakash Agrawal
ID: 18799915
select max(number) as result, name, editor
from table
group by number, editor
0
 
LVL 11

Expert Comment

by:Ved Prakash Agrawal
ID: 18799925
if you want to sort the result you can also tried to add "Order by" Clause
0
 
LVL 20

Assisted Solution

by:Sirees
Sirees earned 100 total points
ID: 18799938
Try this

select a.result, a.name, a.editor
from yourtable a
where a.result = (select max(b.result) from yourtable b where a.editor = b.editor)
0
 

Author Comment

by:bruno_boccara
ID: 18800190
In fact my table is not one table , but a result of a join between 3 tables .....
Sirees Solution works, but not in my case.
About ved17nov's solution, it doesn't work because you didn't include name into the group by.
so it returns me an error msg.
0
 
LVL 2

Accepted Solution

by:
jhshen earned 400 total points
ID: 18800828
This is a sample query to resolve your problem.

select t1.* from mytable t1
inner join (select max(number) as maxNumber, editor from mytable group by editor) t2
on t1.number = t2.maxNumber and t1.editor = t2.editor
order by t1.editor
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now