w3resource

SQL SORTING and FILTERING on HR Database: Display all the information of employees hired before June 21st, 2002

SQL SORTING and FILTERING on HR Database: Exercise-15 with Solution

15. From the following table, write a SQL query to find those employees who were hired before June 21st, 2002. Return all fields.

Sample table: employees


Sample Solution:

SELECT *
 FROM employees
  WHERE hire_date < '2002-06-21';

Sample Output:

employee_id | first_name | last_name |  email   | phone_number | hire_date  |   job_id   |  salary  | commission_pct | manager_id | department_id
-------------+------------+-----------+----------+--------------+------------+------------+----------+----------------+------------+---------------
         102 | Lex        | De Haan   | LDEHAAN  | 515.123.4569 | 2001-01-13 | AD_VP      | 17000.00 |           0.00 |        100 |            90
         203 | Susan      | Mavris    | SMAVRIS  | 515.123.7777 | 2002-06-07 | HR_REP     |  6500.00 |           0.00 |        101 |            40
         204 | Hermann    | Baer      | HBAER    | 515.123.8888 | 2002-06-07 | PR_REP     | 10000.00 |           0.00 |        101 |            70
         205 | Shelley    | Higgins   | SHIGGINS | 515.123.8080 | 2002-06-07 | AC_MGR     | 12000.00 |           0.00 |        101 |           110
         206 | William    | Gietz     | WGIETZ   | 515.123.8181 | 2002-06-07 | AC_ACCOUNT |  8300.00 |           0.00 |        205 |           110
(5 rows)

Relational Algebra Expression:

Relational Algebra Expression: Display all the information of employees  hired before June 21st, 2002.

Relational Algebra Tree:

Relational Algebra Tree: Display all the information of employees  hired before June 21st, 2002.

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display all the information of employees hired before June 21st, 2002 - Duration

Rows:

Query visualization of Display all the information of employees hired before June 21st, 2002 - Rows

Cost:

Query visualization of Display all the information of employees hired before June 21st, 2002 - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to find those employees who work under a manager. Return full name (first and last name), salary, and manager ID.
Next: From the following table, write a SQL query to find those employees whose managers hold the ID 120 or 103 or 145. Return first name, last name, email, salary and manager ID.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS