UNION 語法
select 'tmp' as type , A, B, C from tbl_tmp
union
select 'tmp2' as type , A, B, C from tbl_tmp2
union
select 'tmp2' as type , A, B, C from tbl_tmp3
go
UNION ALL (可排除KEY重覆的DATA)
那 UNION + ORDER BY時,要怎麼寫呢?
select * from
(
select TOP(select count(A) from tbl_tmp) 'tmp' as type , A, B, C from tbl_tmp
union
select TOP(select count(A) from tbl_tmp2) 'tmp2' as type , A, B, C from tbl_tmp2
union
select TOP(select count(A) from tbl_tmp3) 'tmp3' as type , A, B, C from tbl_tmp3
) tbl_ALL
沒有留言:
張貼留言