Reputation: 21
need to return minimum date and other column value for maximum date like below
id name date item
1 First1 24/03/2001 abc
2 First1 20/12/2002 bcd
3 First1 13/02/2003 xyz
4 first2 24/03/2004 nhe
5 first2 20/12/2005 djp
6 first2 13/02/2006 pqr
Required output:
name min_date max_item
First1 24/03/2001 xyz
first2 24/03/2004 pqr
for each contact need to dispaly the min date and item value for max date.
Upvotes: 1
Views: 1006
Reputation: 1269863
Here is one method to get the overall minimum and maximum for the table.
(select t.*
from table t
order by date asc
limit 1
)
union all
(select t.*
from table t
order by date desc
limit 1
)
Upvotes: 1