SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #11 (permalink)  
Old 04-22-2008, 06:39 AM
supriya
 
Posts: n/a
Default ANY answer. Re: i want to get the third highest salary from a table?

SELECT TOP 1 salary FROM Employee( SELECT DISTINCT top 3 salary FROM employee ORDER BY DESC) a ORDER BY salary
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-24-2008, 10:22 AM
Unregistered
 
Posts: n/a
Default ANY answer. Re: i want to get the third highest salary from a table?

Quote:
Originally Posted by lavanya View Post
I am not sure but it will definitely work just try once.


( SELECT salary FROM <tablename> WHERE sal <(SELECT salary FROM <tablename> WHERE sal <(SELECT max(sal) FROM <tablename>)))

This will give the third highest salary from a table.
And for the second highest salary just remove one phrase that is

SELECT salary FROM <tablename> WHERE salary<(SELECT max(salary) FROM <tablename>)


SELECT salary FROM <tablename> WHERE salary<(SELECT max(salary) FROM <tablename> wont work FOR second highest salary.

The correct query is
SELECT max(salary) FROM <tablename> WHERE salary<(SELECT max(salary) FROM <tablename>

to get the third highest salary :

( SELECT max(salary) FROM <tablename> WHERE sal <(SELECT max(salary) FROM <tablename> WHERE sal <(SELECT max(sal) FROM <tablename>)))
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-24-2008, 12:20 PM
vens
 
Posts: n/a
Cool ANY answer. Re: i want to get the third highest salary from a table?

SELECT sal FROM  employees .e WHERE &n=(SELECT DISTINCT(sal) FROM employees WHERE e.sal<=employees.sal);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-30-2008, 12:51 PM
manjunath ps
 
Posts: n/a
Cool ANY answer. Re: i want to get the third highest salary from a table?

Quote:
Originally Posted by Prashant Yadav View Post
table is two fields
Emp_id and Emp_salary

How to get third highest salary without using YOP function.
SELECT * FROM emp a WHERE 2=(SELECT count(*) FROM emp b WHERE a.sal<b.sal);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 05-06-2008, 08:32 AM
Unregistered
 
Posts: n/a
Default ANY answer. Re: i want to get the third highest salary from a table?

Consider the Table Salary_TB with 2 columns empname,salary

SQL
----
SELECT top 1 (salary) FROM Salary_TB  WHERE salary< (SELECT max(salary) FROM Salary_TB WHERE salary<(SELECT max(salary) FROM Salary_TB ) ) ORDER BY salary DESC

i think this can understand all to get third highest salary from a table

Anoop.G
3MenTechnologies
9847160368
anoop.gs@gmail.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 05-20-2008, 12:02 PM
Vishal
 
Posts: n/a
Default ANY answer. Re: i want to get the third highest salary from a table?

y go in for such complex query..try this

SELECT min(Emp_Sal) FROM Employee_Test WHERE Emp_Sal IN
(SELECT DISTINCT top 2 Emp_Sal FROM Employee_Test ORDER BY Emp_Sal DESC)


Vishal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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



All times are GMT. The time now is 09:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8