473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Select 3rd maximum value from table

78
Hi
I have a table named "salary".
Expand|Select|Wrap|Line Numbers
  1. user_id salary
  2. 1          100
  3. 2          200
  4. 3          500
  5. 4          500
  6. 5          500
  7. 6          700
  8. 7          800
  9. 8          700
  10. 9          800  
  11.  
I need to find out 3rd highest salary from this table.
How to write query for that?
Aug 6 '13 #1
8 20717
Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SALARY WHERE salary in
  2. (SELECT s.salary FROM SALARY s ORDER BY column DESC LIMIT 2,1)
Aug 6 '13 #2
Ammu
78
@Basanth thank you for your response
LIMIT 2,1 it will results 500. But there are 3 records.
Is it possble to do it dynamically.?
Aug 6 '13 #3
@Ammu, I didn't fully understand ur question but if want to display all the rows which r equal to 3rd maximum value u can use subquery. I modified my answer check out
Aug 6 '13 #4
Ammu
78
yes it is working now.I have used "=" instead of "in".
thank you
Aug 6 '13 #5
Expand|Select|Wrap|Line Numbers
  1. SELECT name, salary
  2. FROM employees
  3. WHERE salary = (SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees))
Jan 2 '14 #6
/*for 4th highest salary(for remember think limit 3,1 as 3+1). you can try 5th 0r nth */
SELECT DISTINCT(Salary) FROM employee ORDER BY Salary ASC LIMIT 1,1


/*for 2nd highest salary */
SELECT DISTINCT(Salary) FROM employee ORDER BY Salary DESC LIMIT 1,1

/*for 3rd highest salary */
SELECT DISTINCT(Salary) FROM employee ORDER BY Salary DESC LIMIT 2,1
Attached Images
File Type: jpg Capture.jpg (75.9 KB, 981 views)
Feb 13 '14 #7
For retrieving 3rd highest salary, the following query is quite enough than the P: 7 answer

select salary from salary order by salary desc limit 2, 1;
Jul 3 '14 #8
using subqueries we can accomplish the task...works in MySQL and Oracle 10g...
select max(salary) from table_name where salary<(select max(salary) from table_name where salary<(select max(salary) from table_name));...
Sep 23 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've...
7
by: Milos Prudek | last post by:
I need to insert a value = max(value)+1, where max is a select limited by a 'where' clause. Like this: INSERT INTO table (idthread, idsection,txt) VALUES ( (SELECT max(idthread)+1 FROM table...
1
by: Net Virtual Mailing Lists | last post by:
Hello, Lets say I have data like this: value1|value2|value3|value4|....|value(N) ------|------|------|------|----|-------- 100 | 200 | 300 | 400 | | 10 | 20 | | 40 | ...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
6
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value =...
3
by: shalini166 | last post by:
Hi i have table empid,empname...........etc.In my webform i have empname etc.but not empid. i empid is inserted based on the maximum of the empid in the table.At first my table was empty.then...
7
parshupooja
by: parshupooja | last post by:
Hey All, I know its silly question but help me here. I have dropdown which is getting populated dynamic from Database with number like 1,2 ,3, 4, 6,12 etc. By Default I want maximum number to...
1
by: maurizio | last post by:
thank you for your answer actually i've to do some statistics (maximum,minimum,mean,standard deviation,....) of a file of data in which each column is a particular type of data. (the file is a tab...
8
by: omar999 | last post by:
i can a max value of a single column with where clause like this select MAX(Price_Band_1) AS HighestPrice from UK_Specials where ID IN (1,3,5,7,9,10,13,15,17,19,21,23,25,27,29,31,33,35,37) ...
2
by: sandipkumar | last post by:
How to Select maximum value in datatable?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.