What is the difference between UNION and UNION ALL?

后端 未结 26 2876
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 11:28

What is the difference between UNION and UNION ALL?

26条回答
  •  借酒劲吻你
    2020-11-21 12:05

    I add an example,

    UNION, it is merging with distinct --> slower, because it need comparing (In Oracle SQL developer, choose query, press F10 to see cost analysis).

    UNION ALL, it is merging without distinct --> faster.

    SELECT to_date(sysdate, 'yyyy-mm-dd') FROM dual
    UNION
    SELECT to_date(sysdate, 'yyyy-mm-dd') FROM dual;
    

    and

    SELECT to_date(sysdate, 'yyyy-mm-dd') FROM dual
    UNION ALL
    SELECT to_date(sysdate, 'yyyy-mm-dd') FROM dual;
    

提交回复
热议问题