Solved

SQL - How do I get rows with highest value in one column

Posted on 2014-11-14
1
154 Views
Last Modified: 2014-11-14
I have one table with all contracts for cars. One car can have more contracts. For example one contract from 1 januari 2013 until 1 july 2013 and a next contract from 1 sept 2013 until 2 febr 2014.
How can I make a view in SQL 2000 server that shows the last contract of each car.

Example:
number  -  carnumber  -  enddate
123          -  195               -  20130701
158          -  155              -   20141012
168          -  195               -  20140201

As result I want
number  -  carnumber  -  enddate
158          -  155              -   20141012
168          -  195               -  20140301
0
Comment
Question by:cleaclev
[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 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40442307
select (select number from mytable M1 where M.carnumber = M1.carnumber and max(M.enddate) = M1.enddate) as number, carnumber, max(enddate) as enddate
from mytable M
group by carnumber
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

623 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