● union all 重複
● union 不重複
group by 是決定重不重複的關鍵。
select
*
from (
select
ProductName, Money
from
TABLE_A
where
Time between '2009-08-04' and '2010-05-07'
union all
select
ProductName, Money
from
TABLE_B
where
Time between '2009-08-04' and '2010-05-07'
) as tmp
group by ProductName, Money
要做到不重複用 DISTINCT 的效率會比較好
回覆刪除union 本身就有不重複的指令了
你確定要用 union,他的效率會很差,資料大的時候會很明顯
建議你做一下壓力測試