美文网首页
MySQL union

MySQL union

作者: 李得志_春风得意马蹄疾 | 来源:发表于2019-05-09 17:07 被阅读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;

相关文章

网友评论

      本文标题:MySQL union

      本文链接:https://www.haomeiwen.com/subject/hshgoqtx.html