CodeEraFree roadmap

SQL Practice / WHERE clause

SQL WHERE Clause: practice questions with answers

9 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

WHERE keeps only the rows that match a condition. Use comparison operators (=, != or <>, <, >, <=, >=) with numbers, text and dates. Text and dates go in single quotes, and dates use the YYYY-MM-DD format.

SELECT columns FROM table_name WHERE condition;

These questions use the employees table (30 rows). Create it first with the copy-and-paste setup script. Here is the data, so you can check your answers by eye.

See the employees table

Table: employees

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT
1021DavidMillsNULL1998-01-24M2019-12-26IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1023MatthewHill413651998-05-16M2019-05-23IT
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1025MarkWood651201998-10-29M2020-07-30Business Development
1026ElizabethWalker470301998-08-11F2021-06-18NULL
1027BarbaraAndersonNULL1999-12-27F2021-03-14HR
1028JessicaClark638361998-01-24F2021-05-23IT
1029NancyCole636692000-01-26F2019-12-26Finance
1030JoeBrooks440001999-08-05M2021-03-09Business Development

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Display all the records of employees whose joining_date is after 20 March 2022.

Show the answer and the output
SELECT * FROM employees WHERE joining_date > '2022-03-20';

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1006MichaelWatts238001999-04-16M2022-06-09HR
1020DanielElliott440121999-01-21M2023-01-08IT

Question 2Display emp_no, first_name, last_name and department of the employees whose department is 'Finance'.

Show the answer and the output
SELECT emp_no, first_name, last_name, department
FROM employees
WHERE department = 'Finance';

Output

emp_nofirst_namelast_namedepartment
1009LindaPotterFinance
1011SusanHallFinance
1017NancyParkerFinance
1022SarahHarrisonFinance
1029NancyColeFinance

Question 3Display emp_no, salary and department of the employees whose salary is below 35000.

Show the answer and the output
SELECT emp_no, salary, department FROM employees WHERE salary < 35000;

Output

emp_nosalarydepartment
100623800HR
100826392Business Development
101025600IT
101423676IT

Rows where salary is NULL are not returned, because NULL is never less than 35000.

Question 4Display all the records of employees whose birth_date is on or after 24 January 1998.

Show the answer and the output
SELECT * FROM employees WHERE birth_date >= '1998-01-24';

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1002RobertLee694101998-09-02M2019-12-26IT
1004JohnCole362641999-02-01M2021-04-14HR
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1011SusanHall541521999-12-27F2020-08-07Finance
1013MaryGill582461999-01-21F2021-04-30Business Development
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing

Showing the first 12 of 21 rows.

Question 5Display emp_no, first_name and department of employees whose department is other than 'IT'.

Show the answer and the output
SELECT emp_no, first_name, department FROM employees WHERE department != 'IT';

Output

emp_nofirst_namedepartment
1001JamesMarketing
1003MaryBusiness Development
1004JohnHR
1005JenniferMarketing
1006MichaelHR
1008WilliamBusiness Development
1009LindaFinance
1011SusanFinance
1012JosephMarketing
1013MaryBusiness Development
1017NancyFinance
1018BettyHR

Showing the first 12 of 19 rows.

Employees whose department is NULL are also left out. To include them, add OR department IS NULL.

Question 6Display all the records of employees whose emp_no is 1010 or below.

Show the answer and the output
SELECT * FROM employees WHERE emp_no <= 1010;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT

Question 7Display the unique first names of male employees.

Show the answer and the output
SELECT DISTINCT first_name FROM employees WHERE gender = 'M';

Output

first_name
James
Robert
John
Michael
David
William
Richard
Joseph
Thomas
Charles
Christopher
Daniel

Showing the first 12 of 16 rows.

Question 8Display emp_no, first_name and salary, and add 10000 to the salary of employees whose salary is below 25000. Name the new column 'final_salary'.

Show the answer and the output
SELECT emp_no, first_name, salary, salary + 10000 AS final_salary
FROM employees
WHERE salary < 25000;

Output

emp_nofirst_namesalaryfinal_salary
1006Michael2380033800
1014Thomas2367633676

Question 9Display emp_no and the full name as 'full_name' for employees whose emp_no is more than 1015.

Show the answer and the output
SELECT emp_no, CONCAT(first_name, ' ', last_name) AS full_name
FROM employees
WHERE emp_no > 1015;

Output

emp_nofull_name
1016Jessica Clark
1017Nancy Parker
1018Betty Barker
1019Christopher Gibson
1020Daniel Elliott
1021David Mills
1022Sarah Harrison
1023Matthew Hill
1024Anthony Miller
1025Mark Wood
1026Elizabeth Walker
1027Barbara Anderson

Showing the first 12 of 15 rows.

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.