日期:2014-05-16  浏览次数:20483 次

union和union all 的区别
UNION会 把重复的结果去掉,union all 不会

SELECT DISTINCT SUBSTRING(A.last_update,1,4)
FROM fnbl_eben_calendar AS A
WHERE SUBSTRING(A.last_update,1,4)<>SUBSTRING(CURDATE(),1,4)
UNION ALL
SELECT  SUBSTRING(A.last_update,1,4)
FROM fnbl_eben_calendar AS A
WHERE SUBSTRING(A.last_update,1,4)=SUBSTRING(CURDATE(),1,4)
结果
SUBSTRING(A.last_update,1,4)
2010
2009
2011
2011
2011
2011

使用union则是
2010
2009
2011