1.7

IS NULL, BETWEEN, IN Operators

IS NULL

  • Null values indicate an unknown or non-existent value and is different from an empty string (‘ ‘).
  • To test for a null value you use the IS NULL clause
  • The test for a value use IS NOT NULL clause

Example:

SELECT name, IndepYear
FROM country
WHERE IndepYear IS NULL;

Results:

is_null.png

BETWEEN Operators

  • The BETWEEN operator is similar to >= and <=.
  • BETWEEN includes everything between the two values indicated.
  • BETWEEN works with both text and number.


Example:

USE world;
SELECT name, IndepYear
FROM country
WHERE name BETWEEN "Aruba" and "Bahamas";


Results:

between.png

The IN Keyword

  • The IN clause tests whether an expression is equal to a value or values in a list of expressions.
  • The order of the items in the list does not matter.
  • You can use the NOT operator to test for items not in the list.
  • The IN clause may be used with a subquery.


Examples:

USE world;
SELECT name
FROM country
WHERE name IN ('Aruba', 'Barbados', 'Cuba', 'Bahamas')
ORDER BY population ASC;

Results:

IN.png

This content is provided to you freely by BYU-I Books.

Access it online or download it at https://books.byui.edu/learning_mysql/is_null_between_in_o.