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 2005 Forums
 Transact-SQL (2005)
 how to get 2nd largest number from table

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2010-03-05 : 06:31:06
Hello All,
I want to get 2nd largest number from my selected records, is there any way by which it can be achieved(remeber I dont want to use sub query for this purpose)

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-05 : 06:38:19
select top 1 number from
(select top 2 number from table order by number desc)dt
order by number asc


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-03-05 : 06:40:02
On which columns?Please post some sample data.

PBUH
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 08:06:38
Also refer
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-05 : 08:18:20
quote:
Originally posted by madhivanan

Also refer
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx

Madhivanan

Failing to plan is Planning to fail


Hi madhi,
in this link I don't understand the first approach:
(1) Use Inner Join
I think there is a part of code missing.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 08:30:22
quote:
Originally posted by webfred

quote:
Originally posted by madhivanan

Also refer
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx

Madhivanan

Failing to plan is Planning to fail


Hi madhi,
in this link I don't understand the first approach:
(1) Use Inner Join
I think there is a part of code missing.


No, you're never too old to Yak'n'Roll if you're too young to die.


Thanks. Some part of code was not visible. I corrected it now

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-05 : 08:40:04
Now it looks better but it cannot work.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 09:35:27
quote:
Originally posted by webfred

Now it looks better but it cannot work.


No, you're never too old to Yak'n'Roll if you're too young to die.


Thanks. Still there was a problem in displaying the code
I corrected it
Thanks for Testing

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -