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 transfer a table from one schema to another?

560


what are the steps you will take to improve performance of a poor performing query? : Sql server database administration

536


What is dynamic cursor in SQL SERVER?

565


How the authentication mode can be changed?

608


What are commit and rollback in sql?

569






How to rebuild the master database?

581


Which sql server table is used to hold the stored procedure script?

476


How to use values from other tables in update statements in ms sql server?

558


Explain about Normalization?

571


Which joins are sql server default?

513


How to rebuild all indexes on a single table?

591


Do you know how to make remote connection in database?

554


How can we improve performance by using SQL Server profiler?

580


Explain comment on transactions?

558


What are built in functions?

580