Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select second maximum record?

Author  Topic 

nic
Posting Yak Master

209 Posts

Posted - 2002-06-19 : 14:00:51
Hi,
Is there an easy way to get the second maximum record from a table? For example a table has a date column. I don't want the maximum date, I want to get the previous maximum date. Any ideas?

date record
1/1/2001
1/2/2001
1/3/2001
1/4/2001

I want to get the "1/3/2001" record

Thanks



Nic

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-19 : 14:07:57
SELECT Max([date]) FROM myTable
WHERE [date]<(SELECT Max([date]) FROM myTable)


I would recommend that you change the name of the date column to something other than "date", because it's a reserved word and will cause you problems.

Go to Top of Page
   

- Advertisement -