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.
select item_name, flag_column
from table_name
where condition
and not flag_column Schema · Garden Shop Table · products 9 columns · 24 rows
One row per product, with price, cost, and inventory levels.
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.
Related
Date parts, math, and truncation.
Length, case, trimming, slicing, and concatenation.
IS NULL, COALESCE, NULLIF, and null-safe logic.
See why text, numbers, dates, and booleans behave differently.
Compare, sort, and calculate with numeric values.
Filter text values with string literals.