Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Name Mark1 Mark2 Mark3 Mark4

xxx 56 85 79 80


How to select second highest mark from this using sql server?????
Posted
Updated 5-Mar-12 20:23pm
v2

Read the SQL Server books online for UNPIVOT and RANK. If I remember right, this is the textbook example.

See http://technet.microsoft.com/en-us/library/ms177410.aspx[^] and http://msdn.microsoft.com/en-us/library/ms176102.aspx[^]

Hope this helps,
Pablo.
 
Share this answer
 
Comments
Aswathi Narayan 6-Mar-12 2:50am    
Thank u 4 ur reply.. can find solution using the concept pivot table
Hi, try:
SQL
SELECT Name, MAX(XXX) AS SECONDMARK FROM TABLENAME
WHERE XXX <> (SELECT MAX(XXX) FROM TABLENAME)
GROUP BY Name
 
Share this answer
 
v2
Comments
Aswathi Narayan 6-Mar-12 2:41am    
Thank u $ ur reply.. Here Name,Mark1,Mark2,Mark3,Mark4 are 5 seperate columns in the table "Details". then how can i find second highest mark from this using sql server
kishore Rajendran 8-Mar-12 7:07am    
5 marks in 5 columns?why?

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