I have student marks in a student table. I need second
highest mark .Then what will the query for this?

Answer Posted / sanjay

create table test(id int identity,marks int)
insert into test
select 20
union all
select 31
union all
select 33
union all
select 1
union all
select 3
union all
select 100
union all
select 88

select * from test


with data as
(
select marks,row_number() over(order by marks desc) as rno
from test
)
select * from data where rno = 3

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to update values in a table with update statements in ms sql server?

731


What is a non equi join?

733


Can I work with several databases simultaneously? : sql server management studio

731


What is the name of reporting services config file and what’s it’s used for?

119


what is a sub-report?

113






Write the queries for commands like Create Table, Delete table, Drop Table etc.

778


Mention the differences between having and where clause.

783


how you can list all the tables in a database?

734


Do you know what is a with(nolock)?

790


How to use "begin ... End" statement structures in ms sql server?

681


Explain different types of lock modes in sql server 2000?

680


What is enhanced database mirroring in sql server 2008?

668


List all the types of user-defined functions?

683


How to locate and take substrings with charindex() and substring() functions?

694


write an SQL query to list the employees who joined in the month of January?

1377