Comparison Keywords

IS NULL

A column value is NULL if it does not exist. The IS NULL operator is used to display all the rows for columns that do not have a value.

SELECT *
FROM Students
WHERE StudentName IS NULL

Note: it is not possible to test for NULL values with comparison operators such as =. The result of any arithmetic expression involving null is null.

BETWEEN

The BETWEEN operator is used to compare data for a range of values.

SELECT *
FROM Students
WHERE Year BETWEEN 2000 AND 2015

IN

The IN operator is used when you want to match a column with one of several possible values.

SELECT *
FROM Students
WHERE Program IN (‘MM’, ‘MMOR’)

LIKE

The LIKE keyword is used to search entries with a given pattern. For example, the following query returns all the courses with id starting with BAMS.

SELECT *
FROM Courses
WHERE CourseID LIKE ‘BAMS%‘                  (‘BAMS*‘ for MS Access)

The syntax for a condition with LIKE operator is:

expression LIKE pattern

where expression is a character expression such as a column or field, and pattern is a character expression that contains pattern searched. The patterns are expressed using wildcard characters:

  • % allows you to match any string of any length, including zero length (* for MS Access)
  • _ allows you to match on a single character (? for MS Access)

See more about wildcards here: SQL wildcards. See more about LIKE operator: SQL LIKE Condition, SQL LIKE Operator.

EXISTS and UNIQUE keywords are explained in the Nested Queries section.

See more about operators: Oracle SQL Operators, SQL Comparison Keywords.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.