Skip to content
ohsudo, Home

Filtering: AND, IN, LIKE and NULL

Real questions have several conditions. This is also where you'll meet NULL, which trips up nearly everyone once.

● A real database, running in your browser. Nothing you type leaves this page.

Exercise 1 of 7

Two conditions

AND needs both to be true, and OR needs either. Use brackets when you mix them, as AND goes first.

Your task

Show the first_name of employees in department 1 earning 6000 or more.

Tables and columns
    or Ctrl+Enter

    What you'll practice

    1. Two conditions. AND needs both to be true, and OR needs either. Use brackets when you mix them, as AND goes first.
    2. One of several values. IN is a shorter way to write many ORs on one column.
    3. Part of a text. LIKE matches patterns, where % means any text. In PostgreSQL, it's case-sensitive, and ILIKE ignores case. LIKE matches patterns, where % means any text. In SQLite, it ignores case for plain letters by default, unlike PostgreSQL.
    4. Missing values. NULL means "no value", and `= NULL` is never true, not even for NULL. Use IS NULL.
    5. Projects still open. The same goes here: an open project has no end date.
    6. A range of dates. BETWEEN includes both ends. Write dates as YYYY-MM-DD.
    7. True or false. A boolean column can be compared with true or false. SQLite stores booleans as 1 and 0, and understands true and false as those numbers.

    See also