Logical Operators

Logical operators are those operators that use SQL keywords to make comparisons instead of symbols. The logical operators covered in the following subsections are

  • IS NULL

  • BETWEEN

  • IN

  • LIKE

  • EXISTS

  • UNIQUE

  • ALL and ANY

IS NULL

The NULL operator is used to compare a value with a NULL value. For example, you might look for employees who do not have a pager by searching for NULL values in the PAGER column of the EMPLOYEE_TBL table.

The following example shows comparing a value to a NULL value:

ExampleMeaning
WHERE SALARY IS NULLSalary has no value

The following example does not find a NULL value:

ExampleMeaning
WHERE SALARY = NULLSalary has a value containing the letters N-U-L-L
							SELECT EMP_ID, LAST_NAME, FIRST_NAME, PAGER
							FROM EMPLOYEE_TBL ...

Get Sams Teach Yourself SQL in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.