ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

to retrieve second highest value

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL)
View previous topic :: View next topic  
Author Message
daniel_5191



Joined: 26 Jul 2005
Posts: 7
Location: Malaysia

PostPosted: Wed Jul 27, 2005 2:04 am    Post subject: to retrieve second highest value Reply with quote

Admin ,
Sorry , I am newbie in SQL
I wish to retrieve second highest value in a table using SQL statement .

SELECT MIN ( E.marks )
FROM ( SELECT TOP 2 E.marks FROM exam E ORDER BY marks DESC ) exam

Does my coding has any mistake ?

only MS SQL support TOP ? what about MySQL / Access / Sysbase ?


What if i want to retrieve the value in SQL using Access only ? How to code for the SQL statement using Access ?

Thank you for your solution in advanced .
Back to top
View user's profile Send private message MSN Messenger
administrator
Site Admin


Joined: 01 Oct 2004
Posts: 183

PostPosted: Wed Jul 27, 2005 1:48 pm    Post subject: Reply with quote

Something like this should work in SQL Server (you might have to tweak it a little, it's not tested):

SELECT MIN ( MaxMarks ) FROM ( SELECT TOP 2 E.marks As MaxMarks FROM exam E ORDER BY marks DESC )

Only SQL Server has the TOP keyword, but in MySQL you can use the LIMIT keyword instead. In Access you can only order the marks descending and then get the second result in your program...


Cheers,
_________________
Peter
ASP & ASP.NET Articles and Tutorials
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group

SQL Tutorial