Find earliest and latest dates of specified records from a table using SQL
Posted
by tonyyeb
on Stack Overflow
See other posts from Stack Overflow
or by tonyyeb
Published on 2010-03-25T09:10:33Z
Indexed on
2010/03/25
9:13 UTC
Read the original article
Hit count: 490
Hi
I have a table (in MS SQL 2005) with a selection of dates. I want to be able to apply a WHERE statement to return a group of them and then return which date is the earliest from one column and which one is the latest from another column. Here is an example table:
ID StartDate EndDate Person
1 01/03/2010 03/03/2010 Paul
2 12/05/2010 22/05/2010 Steve
3 04/03/2101 08/03/2010 Paul
So I want to return all the records where Person = 'Paul'. But return something like (earliest ) StartDate = 01/03/2010 (from record ID 1) and (latest) EndDate = 08/03/2010 (from record ID 3).
Thanks in advance
© Stack Overflow or respective owner