Goal: Build a report with explicit columns and predicates, then prove how FALSE, NULL, and parentheses affect its rows.
Connect to beer_db as the read-only SQL role student. The real beers table remains intact. A separate provided table, lesson_filter_demo, has four labelled example beers, including one zero IBU and one missing IBU, because the baked beers have neither case.
Set \pset null '(NULL)' so SQL NULLs are visible instead of blank. This changes psql display, not the data.
Compare SELECT * with a named projection on the same first two beers, ordered by name and unique ID. The full query returns twelve columns, including arrays and generated search terms. The second returns only beer name, style, and ABV. AS beer changes the displayed column label, not the stored name. LIMIT 2 is a preview of rows; choosing fewer columns does not itself change which rows qualify.
Show a five-row preview of beers strictly above 7.0% ABV. Sort by ABV, then name and ID so the preview is repeatable. Every displayed ABV must exceed 7.0; beers at or below the threshold are excluded. ABV is NOT NULL in this real table, but that does not mean every row satisfies the predicate.
Find beers with ABV from 5.5 through 7.0, including both endpoints, and IBU below 50. All three conditions must be true. First preview five matching rows, then run the same predicate with COUNT(*). This provided aggregation returns one row containing the full number of matching beers; the preview limit is not part of that count.
Inspect all four lesson_filter_demo rows and the computed ibu > 0 boolean. t means true, f false, and (NULL) unknown. Moon Stout and Sun Lager pass; Zero Bitter fails because 0 is not positive; Mystery Ale is unknown because its IBU is missing. Compare full counts: four rows overall, two passing WHERE. A lower count alone cannot tell you whether FALSE or NULL caused exclusions.
Keep the same fixture and threshold. Count rows with IBU below 200: three qualify, including Zero Bitter, but Mystery Ale is still unknown. Add only OR ibu IS NULL; the count becomes four. Including unknown IBU is an explicit report policy, not something SQL infers for you.
Try ibu = NULL on the same four rows. Expect zero rows, despite the known missing value. Ordinary equality to NULL produces UNKNOWN, even when the left side is NULL; WHERE keeps only TRUE. This failed search is a successful SQL query, not an error.
Use IS NULL to return Mystery Ale with (NULL) IBU. Then use IS NOT NULL to return the other three beers, including Zero Bitter. Missing, zero, and nonzero are different states; these predicates test whether a value is recorded.
Compare the same conditions with and without parentheses: Lager OR Stout AND ABV above 6.0. AND binds more tightly than OR. Without parentheses, Sun Lager is included even at 5.50, together with Moon Stout at 7.00. Grouping the two styles before AND returns only Moon Stout. The fixture names are unique, so ORDER BY name fixes the display order.