ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
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
 
Is This Answer Correct ?    5 Yes 1 No
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)
 
Is This Answer Correct ?    9 Yes 2 No
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);
 
Is This Answer Correct ?    3 Yes 1 No
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)
 
Is This Answer Correct ?    5 Yes 4 No
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
 
Is This Answer Correct ?    2 Yes 1 No
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 ))
 
Is This Answer Correct ?    2 Yes 1 No
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
 
Is This Answer Correct ?    3 Yes 1 No
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
 
Is This Answer Correct ?    1 Yes 1 No
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)
 
Is This Answer Correct ?    2 Yes 1 No
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
 
Is This Answer Correct ?    1 Yes 2 No
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
 
Is This Answer Correct ?    0 Yes 1 No
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)
 
Is This Answer Correct ?    0 Yes 2 No
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)
 
Is This Answer Correct ?    1 Yes 2 No
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
 
Is This Answer Correct ?    2 Yes 5 No
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
 
Is This Answer Correct ?    1 Yes 1 No
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)
 
Is This Answer Correct ?    6 Yes 1 No
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
 
Is This Answer Correct ?    0 Yes 1 No
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
 
Is This Answer Correct ?    0 Yes 1 No
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)
 
Is This Answer Correct ?    0 Yes 1 No
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;
 
Is This Answer Correct ?    1 Yes 1 No
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?
 
Is This Answer Correct ?    0 Yes 1 No
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
 
Is This Answer Correct ?    1 Yes 1 No
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
 
Is This Answer Correct ?    1 Yes 0 No
Sanjay
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
how to give input dynamically to a insert statement in sqlserver HCL2
What is Covering Indexes? Plz explain with example  2
Is trigger fired implicitely?  2
A table contains list of customers and his city with other details. Each customer has a unique number and the table consists millions of data. Query is: I want to retrieve 10 customers from each city, no script, only from single query? Infosys3
Why we need a group by clause?  3
What is the datatype returned by count(*) Asian-CERC18
What is difference beteen Migration and Upgrdation? Satyam4
How to Debug a Stored Procedure? Allianz4
What is Report Server,Report Manager and Report Builder in SSRS 2005?  1
wat is the main diff between sql server 2000and sql server 2005 Jade-Software6
hi i gone though satyam interview. what is Acid Properties? Satyam2
Which data type can be used only on OUTPUT parameters of the stored proceduer?  2
The Difference between 'Count' and 'Count(*)'  12
How to perfor If the table running time is taking 2hours and table is having 10 rows in it?  1
What is database normalization? Digicel5
how many type of subquery?  2
Explain fundamentals of Data ware housing & OLAP?  1
can we call stored Procedure in Function in Sql Server 2000 and vice versa. eSoft2
Difference between server.transfer and server.execute method?  1
Explain the storage models of OLAP?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com