I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answers were Sorted based on User's Feedback
select max(mark) from student where mark <
(select max(mark)from student)
Is This Answer Correct ? | 53 Yes | 14 No |
Answer / madan
This ans. particularly when you want 2nd highest marks?
and not for nth highest marks.
SELECT MAX(mark) FROM student WHERE mark <
(SELECT MAX(mark)FROM student)
Is This Answer Correct ? | 18 Yes | 7 No |
Answer / kumaravel
try using this...
select top 1 from student where marks in (select top 2 from
student order by marks desc)
Is This Answer Correct ? | 16 Yes | 10 No |
Answer / 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 |
Answer / supriya
select max(marks) from student where marks not in (select
max(marks) from student)
Is This Answer Correct ? | 10 Yes | 7 No |
Answer / ravindra singh
select b.marks from (select distinct marks from student)
a,(select distinct marks from student) b
where a.marks >= b.marks
group by b.marks
having count(b.marks)=3
Is This Answer Correct ? | 9 Yes | 7 No |
Answer / naresh
select top 1 age from student where age<(select top 1 age
from student where age<(select distinct max(age) from
student ))
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / rakesh
In Oracle
select marks from
(select marks from
(select marks from students order by marks desc)
where rownum<3
order by marks asc)
where rownum<2
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / suman
select max(mark) from student where mark <
(select max(mark)from student)
Is This Answer Correct ? | 5 Yes | 3 No |
Answer / siva prakasam
SELECT TOP (1) stuMark
FROM Student
WHERE stuMark < (SELECT MAX(stuMark) FROM Student)
ORDER BY stuMark DESC
Is This Answer Correct ? | 4 Yes | 2 No |
What are the main control-of-flow T-SQL constructs?
How to delete database objects with "drop" statements in ms sql server?
How would you choose between a clustered and a non-clustered index?
What happens when unicode strings concatenate with non-unicode strings?
What are null values in ms sql server?
Explain the steps to use transact-sql cursor?
Explain mixed authentication mode of sql server?
What is the diff between Static Queries and Dynamic queries give me some examples
What is abstracting periodical?
What is the maximum length of an alert name?
can any one please send sql quries most used in applications.
What is the use of placing primary key and foreign key constrains on columns.