w3resource

SQL Exercise: List the employees who joined in June 1991

SQL employee Database: Exercise-43 with Solution

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

43. From the following table, write a SQL query to identify the employees who joined the company in June 1991. Return complete information about the employees.

Sample table: employees


Pictorial Presentation:

SQL exercises on employee Database: List the employees who joined in the month of June in 1991

Sample Solution:

SELECT *
FROM employees
WHERE hire_date BETWEEN '1991-06-01' AND '1991-06-30';

OR

SELECT *
FROM employees
WHERE to_char(hire_date,'mon-yyyy')='jun-1991'

Sample Output:

 emp_id | emp_name | job_name | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+----------+------------+------------+---------+------------+--------
  67832 | CLARE    | MANAGER  |      68319 | 1991-06-09 | 2550.00 |            |   1001
(1 row)

Explanation:

The said query in that selects all columns and rows from the 'employees' table where the "hire_date" column, after being formatted as a string with the 'mon-yyyy' format, is equal to the string 'jun-1991'.

The WHERE clause includes those employees hired in June 1991.

The "to_char" function is used to convert the hire_date column into a string with the specified format, 'mon-yyyy'. The 'mon' format code represents the abbreviated month name (e.g. Jan, Feb, Mar), while 'yyyy' represents the year in four digits.

Relational Algebra Expression:

Relational Algebra Expression: List the employees who joined in the month of June in 1991.

Relational Algebra Tree:

Relational Algebra Tree: List the employees who joined in the month of June in 1991.

Practice Online


Sample Database: employee

employee database structure

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

Previous SQL Exercise: List the employees who joined in the year 91.
Next SQL Exercise: List the employees with annual salaries in a ranges.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/employee-database-exercise/sql-employee-database-exercise-43.php