- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the top 3 salaries from a MySQL table with record of Employee Salaries?
For this, use LIMIT and OFFSET. Let us first create a table −
mysql> create table DemoTable867(EmployeeSalary int); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable867 values(63737); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable867 values(899833); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable867 values(23644); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable867 values(89393); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable867 values(534333); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable867 values(889322); Query OK, 1 row affected (0.08 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable867;
This will produce the following output −
+----------------+ | EmployeeSalary | +----------------+ | 63737 | | 899833 | | 23644 | | 89393 | | 534333 | | 889322 | +----------------+ 6 rows in set (0.00 sec)
Here is the query to get first highest salary −
mysql> select distinct(EmployeeSalary) from DemoTable867 order by EmployeeSalary DESC LIMIT 1;
This will produce the following output −
+----------------+ | EmployeeSalary | +----------------+ | 899833 | +----------------+ 1 row in set (0.02 sec)
Here is the query to get second highest salary −
mysql> select distinct(EmployeeSalary) from DemoTable867 order by EmployeeSalary DESC LIMIT 1 OFFSET 1;
This will produce the following output −
+----------------+ | EmployeeSalary | +----------------+ | 889322 | +----------------+ 1 row in set (0.00 sec)
Following is the query to get third highest salary −
mysql> select distinct(EmployeeSalary) from DemoTable867 order by EmployeeSalary DESC LIMIT 1 OFFSET 2;
This will produce the following output −
+----------------+ | EmployeeSalary | +----------------+ | 534333 | +----------------+ 1 row in set (0.00 sec)
- Related Articles
- Display only the employee names with specific salaries in MongoDB documents with employee records?
- How to get the second last record from a table in MySQL?
- Cyber Security Salaries in the Australia
- Cyber Security Salaries in Canada
- Get the last record from a table in MySQL database with Java?
- Cloud Engineer: Job Description and Salaries
- AWS Engineer: Job Roles, Salaries, and the Career Path
- How to get the first and last record of the table in MySQL?
- Change the column name from a MySQL table with Student record?
- How can we fetch a second highest salary of an employee from a MySQL table?
- Get digits from a record in MySQL?
- How to delete last record (on condition) from a table in MySQL?
- How can MySQL FIND_IN_SET() function be used to get the particular record(s) from the table as a result set?
- How to get a specific column record from SELECT query in MySQL?
- Insert record in a MySQL table with Java

Advertisements