Solved

Use of MAX, GROUP BY

Posted on 2007-03-27
5
4,594 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

896 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

13 Experts available now in Live!

Get 1:1 Help Now