Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Please answer this question as soon as possible

This is a discussion on Please answer this question as soon as possible within the SQL forums, part of the Databases category; How to find the Nth largest or Nth smallest salary or number in a table?...

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 06-17-2009
Junior Member
 
Join Date: Jun 2009
Location: India
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
ketaki.gawde is on a distinguished road
Smile Please answer this question as soon as possible

How to find the Nth largest or Nth smallest salary or number in a table?
Reply With Quote
The Following User Says Thank You to ketaki.gawde For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 06-18-2009
Junior Member
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
souji.b4u is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

Hi,

below query is to find the Nth max value in a table:

SELECT min(empno)
FROM(SELECT DISTINCT(empno)
FROM employee
ORDER BY empno desc)
WHERE ROWNUM<= N;

below query is to find the Nth max value in a table:

SELECT max(empno)
FROM(SELECT DISTINCT(empno)
FROM employee
ORDER BY empno asc)
WHERE ROWNUM<= N;
Reply With Quote
  #3 (permalink)  
Old 06-18-2009
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 497
Thanks: 29
Thanked 61 Times in 59 Posts
susarlasireesha is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

Maximum sal

select sal maxsal from (select sal, rn from (select sal, rownum rn from scott.emp order by sal desc) where rn = &rn)

or minimum sal

select sal minsal from (select sal, rn from (select sal, rownum rn from scott.emp order by sal asc) where rn = &rn)
__________________
sireesha
Reply With Quote
  #4 (permalink)  
Old 06-19-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

use max and min function in your query
Reply With Quote
  #5 (permalink)  
Old 06-28-2009
Junior Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dnyaneshm is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

Quote:
Originally Posted by ketaki.gawde View Post
How to find the Nth largest or Nth smallest salary or number in a table?
Please row_number() over(order by Salary)
within derived table & outside row

Select row,Salary
from (Select row_number() over(order by Salary) row, Salary from table1)
Where row = Nth
Reply With Quote
  #6 (permalink)  
Old 07-01-2009
Junior Member
 
Join Date: Jan 2007
Location: Hyderabad
Posts: 11
Thanks: 4
Thanked 1 Time in 1 Post
harini_sree is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

Hi,

select max(sal) from emp where sal<
(select max(sal) from emp where sal<(select max(sal) from emp))
Reply With Quote
  #7 (permalink)  
Old 07-01-2009
Junior Member
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vgirishmtech is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

select max(sal) from emp where sal<
(select max(sal) from emp where sal<(select max(sal) from emp))
Reply With Quote
  #8 (permalink)  
Old 07-03-2009
Junior Member
 
Join Date: Jul 2009
Location: India
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
asad Shaik is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

select max(sal) from emp where sal<
(select max(sal) from emp where sal<(select max(sal) from emp))

Last edited by asad Shaik; 07-03-2009 at 02:56 PM.
Reply With Quote
  #9 (permalink)  
Old 07-04-2009
Junior Member
 
Join Date: Jul 2009
Location: Mumbai(India)
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jitendra_89 is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

what is the difference between dbms and rdbms?
Reply With Quote
  #10 (permalink)  
Old 07-04-2009
Junior Member
 
Join Date: Jul 2009
Location: Mumbai(India)
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jitendra_89 is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

See ,N largest number and N smallest number means the largest and the smallest
value from the column of the given table This can be fine out by the max and min function.
Reply With Quote
  #11 (permalink)  
Old 07-04-2009
Expert Member
 
Join Date: May 2009
Location: Bangalore
Posts: 946
Thanks: 154
Thanked 416 Times in 197 Posts
rijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nice
Re: Please answer this question as soon aaaaaaaaas possi

Hi Jitendra,

DBMS is a ordinary system to maintain the data, whereas RDBMS is the specific type, which follows the concepts of set theory

i.e entity etc.

In DBMS there is no concept of PRIMARY KEY and FOREIGN KEY but it is included in RDBMS.

DBMS contains only flat data whereas in RDBMS there will be some relation between the entities.

If u want to know more differences here is this...


DBMS:

1)In dbms no relationship concept
2)It supports Single User only
3)It treats Data as Files internally
4)It supports 3 rules of E.F.CODD out off 12 rules
5)It requires low Software and Hardware Requirements.
6)FoxPro, IMS are Examples

RDBMS:

1)It is used to establish the relationship concept between two database objects, i.e, tables
2)It supports multiple users
3)It treats data as Tables internally
4)It supports minimum 6 rules of E.F.CODD
5)It requires High software and hardware requirements.
6)SQL-Server, Oracle are examples

&&
one thing ...

Plz post u r queries starting with a new thread...

Thanks & Regards,
Riju.
Reply With Quote
  #12 (permalink)  
Old 07-05-2009
Junior Member
 
Join Date: Jan 2008
Location: Nerul
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ajaymore is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

Quote:
Originally Posted by ketaki.gawde View Post
How to find the Nth largest or Nth smallest salary or number in a table?

select max(col_name),min(col_name) from table_name;
Reply With Quote
  #13 (permalink)  
Old 08-11-2009
Junior Member
 
Join Date: Aug 2009
Location: Delhi
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sunil.bisht12 is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

select sal from emp where sal >=all(select sal from emp);
Reply With Quote
  #14 (permalink)  
Old 08-18-2009
Junior Member
 
Join Date: Aug 2009
Location: ASANSOL
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
rajatbose is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

How can i create procedure in sql for emp... Please tell me some same procedure for emp table from scott, tiger.....
Reply With Quote
  #15 (permalink)  
Old 08-18-2009
Junior Member
 
Join Date: Aug 2009
Location: ASANSOL
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
rajatbose is on a distinguished road
Question Re: Please answer this question as soon aaaaaaaaas possi

Do you know how to create procedure for emp table to extract all the highest salary holder from all the departments....
Reply With Quote
  #16 (permalink)  
Old 08-18-2009
Contributing Member
 
Join Date: Dec 2008
Location: bangalore
Posts: 76
Thanks: 0
Thanked 18 Times in 18 Posts
ecearund is on a distinguished road
Re: Please answer this question as soon aaaaaaaaas possi

@rajabose, why need to go for stored procedures, we can achieve this, by sql analytic functions. For ur reference :
Quote:
select * from ( select e.deptno , e.ename , e.sal , dense_rank() over ( partition by e.deptno order by max(e.sal) desc) topsalary from emp e, dept t where e.deptno=t.deptno group by e.deptno,e.ename,e.sal ) where topsalary <= 10;
the above sql analytic functions retrieves the details of orderwise highest paid employees in each dept.
Reply With Quote
  #17 (permalink)  
Old 09-03-2009
Junior Member
 
Join Date: Aug 2009
Location: Delhi
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sunil.bisht12 is on a distinguished road
Re: Please answer this question as soon as possible

this query is helpfull for you

select * from emp e where &n=(select count(sal) from emp w where e.sal
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to answer this question sripri Interviews 7 09-01-2009 02:06 AM
please answer my question madhoo_09 Java 2 02-26-2009 01:32 AM
Please answer this question desi_guru Testing Issues 1 01-13-2009 07:21 AM


All times are GMT -4. The time now is 03:23 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved