Question
I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Question Submitted By :: Kalyan
I also faced this Question!!
Rank
Answer Posted By
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 1
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
Ravindra Singh
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 2
select max(mark) from student where mark <
(select max(mark)from student)
Pravin More
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 3
select mark from student s
where 1=(select count(*) from student s1
where s1.mark<s.mark);
Kunal Sain
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 4
try using this...
select top 1 from student where marks in (select top 2 from
student order by marks desc)
Kumaravel
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 5
select top 1 marks from marks where marks
<(select max(marks) from marks) order by 1 desc
Sanah
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 6
select top 1 age from student where age<(select top 1 age
from student where age<(select distinct max(age) from
student ))
Naresh
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 7
select top 1 marks from (select top 2 distinct marks from
students order by marks desc)
order by marks
Abhishek Srivastava
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 8
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
Rakesh
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 9
select max(marks) from student where marks not in (select
max(marks) from student)
Supriya
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 10
select a.marks from student a where(select count(b.marks)
from student b where a.marks<=b.marks)=2
Jyoti Bikash Panda
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 11
SELECT TOP 1 Marks (SELECT TOP 2 Marks from Tablename Order
by Marks Desc)From Tablename order by Marks Asc
Dharmendra K. Dixit
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 12
select max(mark) from student where mark not in (select max
(mark) from student)
Koti,khammam
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 13
select max(mark) from student where mark <
(select max(mark)from student)
Suman
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 14
SELECT * FROM(
SELECT ROW_NUMBER() OVER (ORDER BY mark) AS Stu_Rank
FROM student) As T
WHERE Stu_Rank = 2
Sagesh
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 15
4th highest salary
SELECT * FROM(
SELECT ROW_NUMBER() OVER (ORDER BY
grosssalary desc) AS salaryno , *
FROM (
select distinct grosssalary
from salarydetails where inmon='dec' and inyear = 2007
) as a
) As T
WHERE t.salaryno = 4
3rd lowest salary
SELECT * FROM(
SELECT ROW_NUMBER() OVER (ORDER BY
grosssalary ) AS salaryno , *
FROM (
select distinct grosssalary
from salarydetails where inmon='dec' and inyear = 2007
) as a
) As T
WHERE t.salaryno = 3
Dinesh Gupta
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 16
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)
Madan
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 17
with temptab as
(
select row_number() over(order by substring(marks,1,2)) as
rownum,* from Student
)
select * from temptab where rownum=1
Poomanibe [Naturesoft]
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 18
SELECT TOP (1) stuMark
FROM Student
WHERE stuMark < (SELECT MAX(stuMark) FROM Student)
ORDER BY stuMark DESC
Siva Prakasam
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 19
Select max(Marks) from Marks where Marks <
(select max(Marks)from Marks)
Rupa
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 20
select distinct mark from student_mark s
where (select count(distinct s1.mark) from student_mark s1
where s1.mark>=s.mark )=4;
Adarsh Pandey
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 21
I have student marks in a student table. I need all record
where second highest mark .Then what will the query for this?
Shrikant
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 22
SELECT * FROM `student` WHERE class='Six' ORDER BY mark DESC
LIMIT 1,1
Aaaa
Re: I have student marks in a student table. I need second
highest mark .Then what will the query for this?
Answer
# 23
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
Sanjay