zoukankan      html  css  js  c++  java
  • sql语句查询结果合并union all用法_数据库技巧

    --合并重复行
    select * from A
    union 
    select * from B
    
    
    --不合并重复行
    select * from A
    union all
    select * from B
    
    
    按某个字段排序
    --合并重复行
    select *
    from (
    select * from A
    union 
    select * from B) AS T
    order by 字段名
    
    --不合并重复行
    select *
    from (
    select * from A
    union all
    select * from B) AS T
    order by 字段名
    
    //sql server版
    Select * From (
    select top 2 id,adddate,title,url from bArticle where ClassId=1 order by adddate desc) A
    Union All
    Select * From (
    select top 2 id,adddate,title,url from bArticle where ClassId=2 order by adddate desc) B
    Union All
    Select * From (
    select top 2 id,adddate,title,url from bArticle where ClassId=3 order by adddate desc) C
    Union All
    Select * From (
    select top 2 id,adddate,title,url from bArticle where ClassId=4 order by adddate desc) D
    
    
    //mysql版
    Select * From (
    select id,adddate,title,url from bArticle where ClassId=1 order by adddate desc limit 0,2) A
    Union All
    Select * From (
    select id,adddate,title,url from bArticle where ClassId=2 order by adddate desc limit 0,2) B
    Union All
    Select * From (
    select id,adddate,title,url from bArticle where ClassId=3 order by adddate desc limit 0,2) C
    Union All
    Select * From (
    select id,adddate,title,url from bArticle where ClassId=4 order by adddate desc limit 0,2) D
    
  • 相关阅读:
    后可视化编程
    查看图片前进后退效果图
    [置顶] 后可视化编程
    xCAT安装配置文档
    jQuery邮箱验证
    2011级csdnjava张侃—Spring(1)
    [置顶] 后可视化编程时代
    php中Session使用方法详解
    关于浏览器ip代理导致定位错乱问题的坑
    PHPStorm使用技巧及快捷键
  • 原文地址:https://www.cnblogs.com/little-white/p/4172000.html
Copyright © 2011-2022 走看看