MySQL union

2019-05-09  本文已影响0人  李得志_春风得意马蹄疾

MySQL5.7可以使用column union select column,而5.6则不行。建议使用select column union select column这种方式。

以下为案例。

create table t1(title varchar(20));

create table t2(title varchar(20));

create table t3(title varchar(20));

MySQL5.7可以用column直接去union select column。

select title from ( (select title from t1 union select title from t2) union select title from t3 ) t;

MySQL5.6则不能用column直接去union select column,建议使用select column union select column这种方式。

select title from ( select title from (select title from t1 union select title from t2) a union select title from t3 ) t;

MySQL5.7和5.6均可使用以下方式,这里只关注语法的正确性。

select title from(

select title from t1

union

select title from t2

union

select title from t3

) t;

上一篇 下一篇

猜你喜欢

热点阅读