SELECT DISTINCT collapses duplicate projected rows.

highlighted = computed this step

DISTINCT is opt-in

SELECT DISTINCT asks SQL to collapse duplicate projected rows. Without that word, the bag remains a bag. Note: deduplication is explicit in this book.

distinct is explicit\text{distinct is explicit}

DISTINCT collapses the bag

Plain projection had row count 5, while DISTINCT recomputes row count 2. Note: the render shows the deduplicated result.

plain=5,distinct=2\text{plain}=5,\quad \text{distinct}=2

SQL bag/multiset + three-valued NULL logic, deterministic but surprising; tiny finite tables; no engine/perf claims. Set algebra is Book 1.

SELECT DISTINCTdistinct coursearity 1 rows 2Gradesarity 3 rows 5
select_distinctcourseDBOS

The same opt-in applies to identifiers

Plain sid projection recomputes to row count 5, while DISTINCT sid recomputes to row count 3. Note: DISTINCT collapses equal projected rows after projection.

plain sid=5,distinct sid=3\text{plain sid}=5,\quad \text{distinct sid}=3

SQL bag/multiset + three-valued NULL logic, deterministic but surprising; tiny finite tables; no engine/perf claims. Set algebra is Book 1.

SELECT DISTINCT siddistinct sidarity 1 rows 3Gradesarity 3 rows 5
select_distinctsids1s2s3

Summary

DISTINCT is the set-like escape hatch inside bag SQL. Note: bag multiplicity and NULL behavior are here; pure set algebra was Book One.

distinct summary\text{distinct summary}