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. 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 means the discontinued flag is false.

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

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

9 columns · 24 rows
product_id intproduct_name textcategory_id intsupplier_id intprice decimalcost decimalquantity_on_hand intreorder_level intdiscontinued 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.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
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.