The key move is to project first and count rows second:
Read each input row, including repeated category values.
Keep only the selected column.
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
Select query
Plain SELECT projects the category column without deduping.