美文网首页
mysql union和union all 连接2个结果集

mysql union和union all 连接2个结果集

作者: ChenDaXia | 来源:发表于2018-02-02 23:53 被阅读0次

    一般在需要获取2个结果结果集的数据使用union进行连接

    select id,name from t1 union select id,name from  t2
    
    id name
    1 jack
    2 luce

    打上表的标签可以把重复的数据显示出来 或者使用 union all

    select id,name from t1 union select id,name from  t2
    
    id name
    1 jack
    2 luce
    1 jack
    select id,name,'t1' as tab_name from t1 union select id,name,'t2' as tab_name from  t2
    
    id name tab_name
    1 jack t1
    2 luce t2
    1 jack t2

    相关文章

      网友评论

          本文标题:mysql union和union all 连接2个结果集

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