union all
union all 要比union快很多,所以,如果可以確認合併的兩個結果集中不包含重複的數據的話,那麼就使用union all,如下:
儘量使用union all,因為union需要進行排序,去除重複記錄,效率低
union
如果表有多個索引列的時候,用union 替換 where 中的or 效率會提高不少。索引列使用or會造成全表掃描。如果有column 沒有使用索引,就得記得or了。