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)
 second highest id

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-26 : 11:30:00
dhiraj writes "to find out second highest id from a data base .The id's are not in a continuous order"

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-04-26 : 11:42:36
SELECT a.id
FROM (SELECT TOP 2 id
FROM table1
ORDER by id desc) a
WHERE a.id NOT IN (SELECT max(id) from table1)



Duane.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-04-26 : 11:46:12
OR

SELECT TOP 1 a.id
FROM table1 a
WHERE a.id NOT IN (SELECT max(id) from table1)
ORDER by id desc



Damian
Go to Top of Page
   

- Advertisement -