Duplicate Check

The key move is to project first and count rows second:

  1. Read each input row, including repeated category values.
  2. Keep only the selected column.
  3. Notice that equal projected rows still occupy separate output rows. That last count is the SQL bag boundary. A repeated value is still repeated until the query explicitly asks for DISTINCT.

Plain SELECT keeps duplicate projected rows under SQL bag semantics.

highlighted = computed this step

Input table

Start with order categories where one category appears more than once.

Order categories\text{Order categories}
Order categoriesorder_idcategoryo1booko2booko3pen

Select query

Plain SELECT projects the category column without deduping.

SELECT category\text{SELECT category}
SELECT categoryselect categoryarity 1 rows 3OrderCategoriesarity 2 rows 3

Output table

The duplicate category row remains in the output.

bag output\text{bag output}
Outputcategorybookbookpen