InterBase Quick Start: Part IV - Testing for an Unknown Value

From InterBase

Go Up to InterBase Quick Start: Part IV - Using the WHERE Clause


Another type of comparison tests for the absence or presence of a value. Use the IS NULL operator to test whether a value is unknown. To test for the presence of any value, use IS NOT NULL.

Image 025.jpgTesting for NULL

  1. Execute the following query to retrieve the names of employees who do not have phone extensions:
    SELECT last_name,
           first_name,
           phone_ext
    FROM   Employee
    WHERE  phone_ext IS NULL
    

    The image below shows the expected result:

    TutorialWhere11.png
  2. Now execute the statement using IS NOT NULL to retrieve the names of employees who do have phone extensions:
    SELECT last_name,
           first_name,
           phone_ext
    FROM   Employee
    WHERE  phone_ext IS NOT NULL
    

    The image below shows the expected result:

    TutorialWhere12.png

Advance To: