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. Write a query in SQL to list all the employees who joined before or after 1991.

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: Write a query in SQL to list the employees, joined in the month FEBRUARY with a salary range between 1001 to 2000.
Next: Write a query in SQL to list the employees along with department name.

What is the difficulty level of this exercise?



Inviting useful, relevant, well-written and unique guest posts