Skip to content
Worked Examples · Example 13

Q.Using the Employee table (JoinDate column), write SQL queries to

(i) display each employee's name and the year they joined, and
(ii) list the names of employees who joined in the year 2022.
ChseodishaTextbookSubjectiveImportance★★★★★est
94% · 15/16 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Both parts use the date function YEAR(date), which pulls the year number out of a date.

(i) To show each employee's joining year, we apply YEAR to the JoinDate column in the SELECT list:

SELECT Name, YEAR(JoinDate) AS JoinYear
FROM Employee;

For example, a JoinDate of '2022-06-01' gives a JoinYear of 2022.

(ii) To keep only the employees who joined in 2022, we put the same function in a WHERE condition:

SELECT Name FROM Employee
WHERE YEAR(JoinDate) = 2022;
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.