?
Solved

Selecting BOTTOM values

Posted on 2008-10-15
6
Medium Priority
?
248 Views
Last Modified: 2012-06-27
I have the following data in a table

COL1          COL2          COL3
--------         --------        --------
1                 2000           2
1                 2001           1
1                 2002           4
1                 2003           3
2                 2000           1
2                 2001           2
2                 2002           4
2                 2003           3

I need to select the records that had the maximum values of COL3 for each COL1
In other words I need to select the records with the values 1,2002,4 AND 2,2002,4

How would I go about this?
0
Comment
Question by:acsakany
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 13

Expert Comment

by:devsolns
ID: 22722495
select * from tbl where [COL3] = (select max([COL3]) from tbl)
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22722529
select a.* from YourTable a
join (select col1, max(col3) mcol3 from YourTable) b
on a.col1=b.col1
and a.col2=b.col2


or


select * from yourtable a
where col3 = (select max(col3) from yourtable where col1 = a.col1)
0
 

Author Comment

by:acsakany
ID: 22722651
Wouldn't both of these solutions only return one record? I need the MAX for COL3 each time COL1 changes.
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 200 total points
ID: 22722666
No.  Each one will return the max for each col1.

So for your example above:

COL1          COL2          COL3
--------         --------        --------
1                 2002           4
2                 2002           4

0
 
LVL 13

Expert Comment

by:devsolns
ID: 22722740
Nope each will return the max of the column
0
 

Author Closing Comment

by:acsakany
ID: 31506352
Yes you are right. Thank you very much.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

770 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