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.
select item_name, flag_column
from table_name
where condition
and not flag_columnSchema · Garden ShopTable · products9 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.
- Columns: product_name, quantity_on_hand, reorder_level, discontinued.
- Rows: 5 active low-stock products.
- No row should have discontinued set to true.
Related
See why text, numbers, dates, and booleans behave differently.
Compare, sort, and calculate with numeric values.
Filter text values with string literals.
Compare and sort date values chronologically.