MySQL Date and Time Exercises: Query to get the firstname, lastname who joined in the month of June
MySQL Date Time: Exercise-15 with Solution
Write a MySQL query to get the firstname, lastname who joined in the month of June.
Sample table: employees
Code:
-- This SQL query retrieves the first name and last name of employees hired in June.
SELECT
first_name, -- Selecting the 'first_name' column from the 'employees' table.
last_name -- Selecting the 'last_name' column from the 'employees' table.
FROM
employees -- Specifying the 'employees' table.
WHERE
MONTH(HIRE_DATE) = 6; -- Filtering the rows to include only those where the hire date month is June.
Explanation:
- This SQL query selects the first name and last name of employees from the 'employees' table.
- The WHERE clause filters the result set to include only records where the hire date month is June.
- The MONTH() function extracts the month part from the HIRE_DATE column, and it is compared to 6, which represents June.
Sample Output:
first_name last_name Steven King Neena Kochhar Lex De Haan Alexander Hunold Bruce Ernst David Austin Valli Pataballa Diana Lorentz Nancy Greenberg Daniel Faviet John Chen Ismael Sciarra Jose Manuel Urman Luis Popp
Pictorial Presentation of the above query:
MySQL Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a MySQL query to display the current date in the specified format.
Next:Write a MySQL query to get the years in which more than 10 employees joined.
What is the difficulty level of this exercise?
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://w3resource.com/mysql-exercises/date-time-exercises/write-a-query-to-get-the-firstname-lastname-who-joined-in-the-month-of-june.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics