Rullst AcademyRullst Academy/Lesson
Databases and SQL I · Lesson 04 / 12

Filter missing values carefully

Use WHERE, parentheses and IS NULL; distinguish empty, zero and missing.

Learning paths16 min

Let's discover together

  1. 1

    WHERE keeps true conditions. AND requires both; OR accepts at least one. AND takes precedence, but parentheses make intent explicit: (category = ... OR category = ...) AND stock > 0.

  2. 2

    Use IS NULL, not = NULL. Ordinary NULL comparisons produce unknown, which is not true in WHERE. Our model uses returned IS NULL for open loans; that meaning was a modeling choice.

  3. 3

    Kit 3 has empty note text; kits 1 and 4 have NULL. Zero can be a known quantity, empty can be known text, NULL can mean missing. Do not automatically interchange them.

  4. 4

    Run both queries. Replace IS NULL with = NULL and explain the result. Then look for note equal to empty text and compare ids.

Your data workbench

Our model: kits.id ← loans.kit_id. One material can have many loans; names may repeat. We use fictional data only.

Predict before opening the reference. It shows verified output from the original example, not execution of your text. Run your changes with the kit on your computer.

-- Filter missing values carefully
SELECT id, kit_id FROM loans WHERE returned IS NULL ORDER BY id;
SELECT id FROM kits WHERE note IS NULL ORDER BY id;
Compare with reference output
[
  {
    "columns": [
      "id",
      "kit_id"
    ],
    "rows": [
      [
        1,
        1
      ],
      [
        3,
        2
      ],
      [
        4,
        3
      ]
    ]
  },
  {
    "columns": [
      "id"
    ],
    "rows": [
      [
        1
      ],
      [
        4
      ]
    ]
  }
]

Run the command in the extracted folder’s terminal. Use python3 on macOS/Ubuntu or py if that is your Windows launcher. Every run starts in memory; read README.md for saving files and recovery practice.

python lab.py run lesson.sql
My files and GitHub

The editor saves your .sql draft in this browser. Download it and replace lesson.sql in the kit; for the final project, availability.sql. The ZIP remains the original template. GitHub publishing sends only the confirmed file, without executing SQL or sending a database.

Official links and next step

✦
YOUR MISSION

Use WHERE, parentheses and IS NULL; distinguish empty, zero and missing.

Now it's your turn

Discovery workshop

Read, predict and check

Use WHERE, parentheses and IS NULL; distinguish empty, zero and missing.
Build your answers and check when you are ready.
A moment to understand

How do you query open loans?

I need a hint

Use IS NULL, not = NULL. Ordinary NULL comparisons produce unknown, which is not true in WHERE. Our model uses returned IS NULL for open loans; that meaning was a modeling choice.

Loading your journey…

Take it with you

Write a filter for missing or empty notes. Predict each id and compare with execution.

At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.