w3resource

SQL exercises on employee Database: List all the employees who joined before or after 1991

SQL employee Database: Exercise-51 with Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

51. From the following table, write a SQL query to find those employees who joined before or after the year 1991. Return complete information about the employees.

Sample table: employees


Pictorial Presentation:

SQL exercises on employee Database: List all the employees who joined before or after 1991

Sample Solution:

SELECT *
FROM employees
WHERE to_char(hire_date,'YYYY') NOT IN ('1991');

OR

SELECT *
FROM employees
WHERE to_char (hire_date,'YYYY') NOT LIKE '1991';

Sample Output:

 emp_id | emp_name | job_name | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+----------+------------+------------+---------+------------+--------
  67858 | SCARLET  | ANALYST  |      65646 | 1997-04-19 | 3100.00 |            |   2001
  63679 | SANDRINE | CLERK    |      69062 | 1990-12-18 |  900.00 |            |   2001
  68736 | ADNRES   | CLERK    |      67858 | 1997-05-23 | 1200.00 |            |   2001
  69324 | MARKER   | CLERK    |      67832 | 1992-01-23 | 1400.00 |            |   1001
(4 rows)

Practice Online


Sample Database: employee

employee database structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following table, write a SQL query to find those employees who joined in the month FEBRUARY with a salary range between 1001 to 2000 (Begin and end values are included.). Return complete information about the employees.
Next: From the following table, write a SQL query to find employees along with department name. Return employee ID, employee name, job name, manager ID, hire date, salary, commission, department ID, and department name.

What is the difficulty level of this exercise?