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
    
  • 相关阅读:
    python系列十二:python3模块
    python系列十一:python3数据结构
    python系列十:python3函数
    python系列九:python3迭代器和生成器
    python系列八:Python3条件控制&循环语句
    python系列七:Python3字典dict
    python系列六:Python3元组tuple
    Linux Ubuntu 安装SSH服务
    Linux Ubuntu 查看IP
    Linux 基础命令
  • 原文地址:https://www.cnblogs.com/little-white/p/4172000.html
Copyright © 2011-2022 走看看