Home > Archive > Microsoft SQL Server forum > September 2005 > min(date) + 1









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author min(date) + 1
imani_technology_spam@yahoo.com

2005-09-21, 8:23 pm

I know you can use the min function to get the first date within a
recordset. However, is there a way to get the second date in a
recordset? In other words, is there a way to get "min(date) + 1" or a
"next-to-earliest date" essentially?

Danny

2005-09-21, 8:23 pm

Try somehthing like...

select min(a.date) from (select date from table b where b.date > (select
min(c.date) from table c)) a

This should get the next earliest date not necessarily the next min date if
there are duplicate min dates.


< imani_technology_spa
m@yahoo.com> wrote in message
news:1127338921.903049.218810@z14g2000cwz.googlegroups.com...
>I know you can use the min function to get the first date within a
> recordset. However, is there a way to get the second date in a
> recordset? In other words, is there a way to get "min(date) + 1" or a
> "next-to-earliest date" essentially?
>



masri999@gmail.com

2005-09-22, 7:23 am


select top 1 a.date from
(select top 2 date from table order by date ) a
order by a.date desc

Hugo Kornelis

2005-09-22, 8:24 pm

On Wed, 21 Sep 2005 23:21:52 GMT, Danny wrote:

>Try somehthing like...
>
>select min(a.date) from (select date from table b where b.date > (select
>min(c.date) from table c)) a
>
>This should get the next earliest date not necessarily the next min date if
>there are duplicate min dates.


Hi Danny,

No need to use a derived table, though. This'll work as well:

SELECT MIN(a.date)
FROM table AS a
WHERE a.date > (SELECT MIN(b.date) FROM b.table))

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com