Skip to content
/ Chapter 2 · Data Types Before Deep Querying
Lesson 2.5 · garden_shop
Lesson 2.5

Booleans and Flag Columns in SQL

Boolean columns answer yes/no questions and are useful for simple flags.

A boolean column stores true or false (and, when the column is nullable, possibly NULL). These columns often act as flags, such as whether a customer is active or a product has been discontinued.

You can compare a boolean column to true or false, but a shorter pattern is to use the column directly. not discontinued keeps rows where the discontinued flag is false; a null flag wouldn't pass that filter.

Pattern
select item_name, flag_column
from table_name
where condition
  and not flag_column
Schema · Garden Shop Table · products 9 columns · 24 rows
Table · products

One row per product, with price, cost, and inventory levels.

9 columns · 24 rows
product_id int product_name text category_id int supplier_id int price decimal cost decimal quantity_on_hand int reorder_level int discontinued bool
Your task

Show the product name, quantity on hand, reorder level, and discontinued flag for products that are below their reorder level, excluding discontinued products.

·

Run your query to inspect the result.

Expected answer
  • Columns: product_name, quantity_on_hand, reorder_level, discontinued.
  • Rows: 5 active low-stock products.
  • No row should have discontinued set to true.