RianAcademy
Search
⌘
K
Premium

IS NULL, BETWEEN, IN Operators

We have already familiarized ourselves with the syntax of the WHERE operator and comparison operators, but in addition to them, we can use the following useful operators in conditional queries:

  • IS NULL
  • BETWEEN
  • IN

Let's look at their application.

IS NULL

The IS NULL operator allows you to check whether a field has no value.

For example, let's select all teachers who do not have a middle name:

MySQL 8.4
SELECT * FROM Teacher
WHERE middle_name IS NULL;
idfirst_namemiddle_namelast_name
10YUrij<NULL>Krylov
11Andrej<NULL>Evseev

To use negation, i.e. if we want to find all records where the field is not equal to NULL, we must use the following syntax:

MySQL 8.4
SELECT * FROM Teacher
WHERE middle_name IS NOT NULL;

BETWEEN

The BETWEEN min AND max operator allows you to find out if the checked value of the column is located in the interval between min and max, including the values min and max themselves.

It is identical to the condition:

MySQL 8.4
... WHERE field >= min AND field <= max

This operator is used as follows:

MySQL 8.4
SELECT * FROM Payments
WHERE unit_price BETWEEN 100 AND 500;

All records from the Payments table where the value of the unit_price field is from 100 to 500 will be returned as a result.

IN

The IN operator allows you to find out if the checked value of the column is included in a list of certain values.

MySQL 8.4
SELECT * FROM FamilyMembers
WHERE status IN ('father', 'mother');
member_idstatusmember_namebirthday
1fatherHeadley Quincey1960-05-13T00:00:00.000Z
2motherFlavia Quincey1963-02-16T00:00:00.000Z
6fatherErnest Forrest1961-09-11T00:00:00.000Z
7motherConstance Forrest1968-09-06T00:00:00.000Z
Tasks for self-testing
0 / 3
1. Print records containing NULL

Print the first_name and last_name of the students from the table Student missing middle_name.
Class
id
INT
name
VARCHAR
Schedule
id
INT
date
DATE
class
INT
number_pair
INT
teacher
INT
subject
INT
classroom
INT
Student
id
INT
first_name
VARCHAR
middle_name
VARCHAR
last_name
VARCHAR
birthday
DATE
address
VARCHAR
Student_in_class
id
INT
class
INT
student
INT
Subject
id
INT
name
VARCHAR
Teacher
id
INT
first_name
VARCHAR
middle_name
VARCHAR
last_name
VARCHAR
Timepair
id
INT
start_pair
TIME
end_pair
TIME
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Result
Class
Schedule
Student
Student_in_class
Subject
Teacher
Timepair

Run a query to see the result, or open a table above