Answer for Exercise 1 - SQL Fundamentals (SELECT & Filtering Statements)
Answer for Exercise 1 - SQL Fundamentals (SELECT & Filtering Statements)
Database: employees_db
Assume you have a table called employees with the following structure:
Here are the definitions for each column in the employees table:
department The department where the employee works (e.g., IT, HR, Finance,
Marketing).
hire_date The date the employee was hired in the format YYYY-MM-DD.
1. SELECT Statement
SQL Query:
SQL Query:
Expected Output:
department
IT
HR
Finance
Marketing
3. ORDER BY Statement
Question: Retrieve all employees' first and last names, ordered by salary in descending
order.
SQL Query:
SELECT first_name,
last_name,
salary
FROM employees
Expected Output:
SQL Query:
SELECT first_name,
last_name,
salary
FROM employees
LIMIT 5;
Expected Output:
SQL Query:
SELECT first_name,
last_name,
department
FROM employees
Expected Output:
John Doe IT
Sarah Brown IT
6. AND Statement
Question: Find employees who work in the Finance department AND have a salary
greater than 58,000.
SQL Query:
SELECT first_name,
last_name,
department,
salary
FROM employees
Expected Output:
SQL Query:
SELECT first_name,
last_name,
department
FROM employees
Expected Output:
Jane Smith HR
Jessica Moore HR
8. NOT Statement
SQL Query:
FROM employees
Expected Output:
Jane Smith HR
Question: Find employees who are in the HR, IT, or Finance departments.
SQL Query:
SELECT first_name,
last_name,
department
FROM employees
Expected Output:
John Doe IT
Jane Smith HR
Question: Find employees who are in the IT department, have a salary greater than
50,000, and are located in New York.
SQL Query:
FROM employees
Expected Output:
SQL Query:
SELECT first_name,
last_name,
department,
salary
FROM employees
SQL Query:
FROM employees
SQL Query:
SELECT first_name,
last_name,
department,
salary,
hire_date
FROM employees
SQL Query:
FROM employees
LIMIT 3;
15. Combining WHERE, AND, OR, NOT, ORDER BY, and LIMIT
SQL Query:
SELECT first_name,
last_name,
department,
salary,
city
FROM employees
LIMIT 5;