SELECT C1,C2,C3 FROM T1 ORDER BY C1
UNION ALL
SELECT C1,C2,C3 FROM T2 ORDER BY C1
当执行上述SQL语句时,会报错。
这时候需要使用临时表,如下:
SELECT * FROM
(SELECT C1,C2,C3 FROM T1 ORDER BY C1) t1
UNION ALL
SELECT * FROM
(SELECT C1,C2,C3 FROM T2 ORDER BY C1) t2
PS:UNION (ALL) 的使用条件是,列名、数据类型和列数都要一一对应。
网友评论