CodeEraFree roadmap

SQL Practice / BETWEEN and IN

SQL BETWEEN and IN Operators: practice questions with answers

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

BETWEEN a AND b checks a range, and both ends are included. IN (...) checks a list of values and is a shorter way to write several OR conditions. Add NOT in front of either to get the opposite.

WHERE column BETWEEN low AND high
WHERE column NOT BETWEEN low AND high
WHERE column IN (v1, v2, v3)
WHERE column NOT IN (v1, v2, v3)

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 1Get all the details of employees who joined the company between 1 March 2019 and 1 April 2021.

Show the answer and the output
SELECT * FROM employees WHERE joining_date BETWEEN '2019-03-01' AND '2021-04-01';

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1005JenniferGill489411996-06-05F2019-06-28Marketing
1008WilliamHill263921999-10-21M2019-09-30Business Development
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
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 19 rows.

Different from the PDF: The PDF had a space inside the date ('2019-03- 01'), which gives a wrong result. Fixed.

Question 2Get first_name, last_name and salary of employees whose last name is Gill, Hill, Mills or Hall.

Show the answer and the output
SELECT first_name, last_name, salary FROM employees WHERE last_name IN ('Gill', 'Hill', 'Mills', 'Hall');

Output

first_namelast_namesalary
JenniferGill48941
DavidMills39400
WilliamHill26392
SusanHall54152
MaryGill58246
DavidMillsNULL
MatthewHill41365

Question 3Display all the details of employees whose salary is not between 40000 and 50000.

Show the answer and the output
SELECT * FROM employees WHERE salary NOT BETWEEN 40000 AND 50000;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
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
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

Showing the first 12 of 20 rows.

Employees with a NULL salary are not returned.

Question 4Get emp_no, first_name, salary and department of employees whose department is not Marketing, HR or Finance. Name the department column 'other_department'.

Show the answer and the output
SELECT emp_no, first_name, salary, department AS other_department
FROM employees
WHERE department NOT IN ('Marketing', 'HR', 'Finance');

Output

emp_nofirst_namesalaryother_department
1002Robert69410IT
1003Mary39518Business Development
1007David39400IT
1008William26392Business Development
1010Richard25600IT
1013Mary58246Business Development
1014Thomas23676IT
1016JessicaNULLIT
1020Daniel44012IT
1021DavidNULLIT
1023Matthew41365IT
1024Anthony56794Business Development

Showing the first 12 of 15 rows.

Employees with no department are not returned: NULL NOT IN (...) is unknown, not true.

Question 5Get all the details of employees whose emp_no is more than 1020 and whose first name is David, Mark or Joe.

Show the answer and the output
SELECT * FROM employees WHERE emp_no > 1020 AND first_name IN ('David', 'Mark', 'Joe');

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1021DavidMillsNULL1998-01-24M2019-12-26IT
1025MarkWood651201998-10-29M2020-07-30Business Development
1030JoeBrooks440001999-08-05M2021-03-09Business Development

Question 6Get all the details of female employees born between 9 July 1997 and 9 July 1998.

Show the answer and the output
SELECT * FROM employees
WHERE gender = 'F' AND birth_date BETWEEN '1997-07-09' AND '1998-07-09';

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1003MaryWood395181997-11-07F2019-09-12Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1028JessicaClark638361998-01-24F2021-05-23IT

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