BrightLight Tutorials
Data Analytics
Exercise 1: SQL Fundamentals
Database: employees_db
Assume you have a table called employees with the following structure:
id first_name last_name department salary hire_date city
1 John Doe IT 55000 2018-06-15 New York
2 Jane Smith HR 48000 2019-07-20 Chicago
3 Mike Johnson Finance 60000 2017-09-30 Los Angeles
4 Sarah Brown IT 53000 2021-03-25 New York
5 David White Marketing 52000 2016-04-10 San Francisco
6 Emily Davis IT 62000 2015-02-14 Chicago
7 Robert Wilson Finance 59000 2019-10-01 Houston
8 Jessica Moore HR 51000 2018-05-22 Los Angeles
9 Daniel Clark Marketing 53000 2022-06-01 Chicago
10 Laura Hall IT 50000 2020-08-10 San Francisco
Questions
1. SELECT Statement
Write a SQL query to retrieve all columns from the employees table.
2. SELECT DISTINCT Statement
Write a SQL query to find all the unique departments in the employees table.
3. ORDER BY Statement
Write a SQL query to retrieve all employees' first and last names, ordered by salary in
descending order.
4. LIMIT Statement
Write a SQL query to retrieve the top 5 highest-paid employees.
5. WHERE Statement
Write a SQL query to find employees who work in the IT department.
6. AND Statement
Write a SQL query to find employees who work in the Finance department AND have a
salary greater than 58,000.
7. OR Statement
Write a SQL query to find employees who work in the HR department OR the Marketing
department.
8. NOT Statement
Write a SQL query to find employees who do not work in the IT department.
9. IN Statement
Write a SQL query to find employees who are in the HR, IT, or Finance departments.
10. Combining Conditions
Write a SQL query to find employees who are in the IT department, have a salary greater
than 50,000, and are located in New York.
11. Combining WHERE, AND, and ORDER BY
Write a SQL query to retrieve the first and last names of employees who work in the
Finance or Marketing department, earn more than 52,000, and order the results by
salary in descending order.
12. Combining SELECT DISTINCT, WHERE, and IN
Write a SQL query to find all the unique cities where employees work, excluding those
in the IT and HR departments.
13. Combining WHERE, NOT, AND, and ORDER BY
Write a SQL query to retrieve employees who are NOT in the Finance department,
have a salary greater than 50,000, and order the results by hire date in ascending
order.
14. Combining WHERE, OR, IN, and LIMIT
Write a SQL query to find the first 3 employees who work in either Chicago or Los
Angeles and belong to the IT or Marketing department.