Does the order of columns matter in a group by clause?

前端 未结 5 1142

If I have two columns, one with very high cardinality and one with very low cardinality (unique # of values), does it matter in which order I group by?

Here\'s an ex

5条回答
  •  我在风中等你
    2020-12-13 17:28

    If I have two columns, one with very high cardinality and one with very low cardinality (unique # of values), does it matter in which order I group by?

    Query-1

    SELECT spec_id, catid, spec_display_value, COUNT(*) AS cnt  FROM tbl_product_spec 
    GROUP BY spec_id, catid, spec_display_value ;
    

    Query-2

    SELECT spec_id, catid, spec_display_value, COUNT(*) AS cnt  FROM tbl_product_spec FORCE INDEX(idx_comp_spec_cnt)
    GROUP BY catid, spec_id,spec_display_value;
    

    Both are equal , order doesn't work in group by clause.

提交回复
热议问题