SQL Practice Problem

Employees hired after a date

Easy Strings & Dates

Schema and sample data

Employees
emp_idnamehire_datedepartment
1Ava Torres2021-03-15Engineering
2Ben Ncube2022-01-01Sales
3Cara Singh2023-06-20Engineering
4Deng Liu2020-11-05Support
5Emma Rossi2022-09-12Sales
6Farid Khan2024-02-28Support
Show setup SQL (copy to run)
CREATE TABLE Employees (
    emp_id     INT PRIMARY KEY,
    name       VARCHAR(50) NOT NULL,
    hire_date  DATE NOT NULL,
    department VARCHAR(30)
);

INSERT INTO Employees (emp_id, name, hire_date, department) VALUES
(1, 'Ava Torres', '2021-03-15', 'Engineering'),
(2, 'Ben Ncube',  '2022-01-01', 'Sales'),
(3, 'Cara Singh', '2023-06-20', 'Engineering'),
(4, 'Deng Liu',   '2020-11-05', 'Support'),
(5, 'Emma Rossi', '2022-09-12', 'Sales'),
(6, 'Farid Khan', '2024-02-28', 'Support');
Your task

From the Employees table, return the name and hire_date of every employee hired on or after 2022-01-01. Sort the result by hire_date from earliest to latest.

Expected result

Your query should return
namehire_date
Ben Ncube2022-01-01
Emma Rossi2022-09-12
Cara Singh2023-06-20
Farid Khan2024-02-28
Show hint

You need a WHERE clause that compares hire_date against the cutoff date. Because the wording says "on or after", the comparison is >= so an employee hired exactly on 2022-01-01 must be kept. Write the literal as a quoted string in YYYY-MM-DD form.

Try to write the query yourself before you open this.

Show solution and explanation
SELECT name, hire_date
FROM Employees
WHERE hire_date >= '2022-01-01'
ORDER BY hire_date ASC;

The WHERE hire_date >= '2022-01-01' filter keeps only rows whose hire date falls on or after the cutoff. Ava Torres (2021-03-15) and Deng Liu (2020-11-05) are hired before the cutoff, so they are dropped. Ben Ncube was hired exactly on 2022-01-01, and because the comparison is >= (not a strict >), that row stays. Reading "on or after" as a strict greater-than is the most common mistake here.

SQL Server compares a DATE column against a string literal by implicitly converting the string to a date. The YYYY-MM-DD format is the safe, unambiguous choice because it is interpreted the same way regardless of the server language or regional settings. Other formats like 01/02/2022 can be read as either January 2 or February 1.

ORDER BY hire_date ASC then sorts the four surviving rows from earliest to latest. ASC is the default, so it could be omitted, but stating it makes the intent explicit. If you needed a bounded range instead of an open one, you would add an upper bound, for example hire_date >= '2022-01-01' AND hire_date < '2023-01-01'.

Keep practising

Work through more Easy exercises, or test yourself with the SQL interview questions.