Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
VB
id name mid
===========
1   A    null
2   B     1
3   C    null
4   D     1


In the above table i want to write the query to fetch the second highest id using linque

How can i do that
Posted

http://www.functionx.com/csharp/linq/Lesson03.htm[^]

You might have to do a Distinct first:

var c = (from x in olist order by mid descending select mid).Distinct().Skip(1).First();
 
Share this answer
 
v3
Like this:

C#
int secondHighest = (from Id in MyTable
                     orderby Id descending
                     select Id).Skip(1).First();


Read more about Skip on MSDN:

http://msdn.microsoft.com/en-us/library/bb358985.aspx[^]
 
Share this answer
 
Comments
Basheer Belgod 14-Jan-13 8:42am    
Thank you its working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900