SQL Exercise: Find those employees who earn below 6000
SQL SORTING and FILTERING on HR Database: Exercise-1 with Solution
1. From the following table, write a SQL query to find those employees whose salaries are less than 6000. Return full name (first and last name), and salary.
Sample table: employees
Sample Solution:
SELECT first_name ||' '||last_name AS Full_Name, salary
FROM employees
WHERE salary < 6000;
Sample Output:
full_name | salary -------------------+--------- David Austin | 4800.00 Valli Pataballa | 4800.00 Diana Lorentz | 4200.00 Alexander Khoo | 3100.00 Shelli Baida | 2900.00 Sigal Tobias | 2800.00 Guy Himuro | 2600.00 Karen Colmenares | 2500.00 Kevin Mourgos | 5800.00 Julia Nayer | 3200.00 Irene Mikkilineni | 2700.00 James Landry | 2400.00 Steven Markle | 2200.00 Laura Bissot | 3300.00 Mozhe Atkinson | 2800.00 James Marlow | 2500.00 TJ Olson | 2100.00 Jason Mallin | 3300.00 Michael Rogers | 2900.00 Ki Gee | 2400.00 Hazel Philtanker | 2200.00 Renske Ladwig | 3600.00 Stephen Stiles | 3200.00 John Seo | 2700.00 Joshua Patel | 2500.00 Trenna Rajs | 3500.00 Curtis Davies | 3100.00 Randall Matos | 2600.00 Peter Vargas | 2500.00 Winston Taylor | 3200.00 Jean Fleaur | 3100.00 Martha Sullivan | 2500.00 Girard Geoni | 2800.00 Nandita Sarchand | 4200.00 Alexis Bull | 4100.00 Julia Dellinger | 3400.00 Anthony Cabrio | 3000.00 Kelly Chung | 3800.00 Jennifer Dilly | 3600.00 Timothy Gates | 2900.00 Randall Perkins | 2500.00 Sarah Bell | 4000.00 Britney Everett | 3900.00 Samuel McCain | 3200.00 Vance Jones | 2800.00 Alana Walsh | 3100.00 Kevin Feeney | 3000.00 Donald OConnell | 2600.00 Douglas Grant | 2600.00 Jennifer Whalen | 4400.00 (50 rows)
Code Explanation:
The said query in SQL which retrieves the full name (concatenation of first name and last name with a space in between) and salary columns of employees whose salary is less than 6000.
The result will be a table with two columns: "Full_Name" and "salary", with each row representing an employee that meets the condition.
Practice Online

Query Visualization:
Duration:

Rows:

Cost:

Contribute your code and comments through Disqus.
Previous SQL Exercise: SQL SORTING and FILTERING on HR Database Exercises Home
Next SQL Exercise: Find those employees who earn more than 8000.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
Difference between natural join and inner join
One significant difference between INNER JOIN and NATURAL JOIN is the number of columns returned-
Consider:
TableA TableB +------------+----------+ +--------------------+ |Column1 | Column2 | |Column1 | Column3 | +-----------------------+ +--------------------+ | 1 | 2 | | 1 | 3 | +------------+----------+ +---------+----------+
The INNER JOIN of TableA and TableB on Column1 will return
SELECT * FROM TableA AS a INNER JOIN TableB AS b USING (Column1); SELECT * FROM TableA AS a INNER JOIN TableB AS b ON a.Column1 = b.Column1;
+------------+-----------+---------------------+ | a.Column1 | a.Column2 | b.Column1| b.Column3| +------------------------+---------------------+ | 1 | 2 | 1 | 3 | +------------+-----------+----------+----------+
The NATURAL JOIN of TableA and TableB on Column1 will return:
SELECT * FROM TableA NATURAL JOIN TableB +------------+----------+----------+ |Column1 | Column2 | Column3 | +-----------------------+----------+ | 1 | 2 | 3 | +------------+----------+----------+
Ref: https://bit.ly/3AG5CId
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook