zoukankan      html  css  js  c++  java
  • SQLite3神奇的UNION、UNION ALL与LIMIT组合

    以此备忘:

    xxxxxx@ubuntu:~/sqlite/SQLite-036ebf72_orig_3.18.2$ ./sqlite3 t.db
    SQLite version 3.18.2 2017-06-17 09:59:36
    Enter ".help" for usage hints.
    sqlite> create table t1(id integer primary key autoincrement, data text);
    sqlite> create table t2(id integer primary key autoincrement, data text);
    sqlite> insert into t1(data) values('t1_d1');
    sqlite> insert into t1(data) values('t1_d2');
    sqlite> insert into t2(data) values('t2_d1');
    sqlite> insert into t2(data) values('t2_d2');
    sqlite> select * from t1 union select * from t2;
    1|t1_d1
    1|t2_d1
    2|t1_d2
    2|t2_d2
    sqlite> select * from(select * from(select * from t1 limit 1) union select * from(select * from t2 limit 1));
    1|t1_d1
    1|t2_d1
    sqlite> select * from(select * from(select * from t1 limit 1) union all select * from(select * from t2 limit 1));
    1|t1_d1
    sqlite>
    sqlite>
    sqlite> select * from(select * from(select * from t1 limit 2) union all select * from(select * from t2 limit 2));
    1|t1_d1
    2|t1_d2
    sqlite> select * from(select * from(select * from t1) union all select * from(select * from t2 limit 2));
    1|t1_d1
    2|t1_d2
    1|t2_d1
    2|t2_d2
    sqlite> select * from(select * from(select * from t1 limit 2) union all select * from(select * from t2));
    1|t1_d1
    2|t1_d2
    sqlite> select * from(select * from(select * from t1 limit 2) union select * from(select * from t2 limit 2));
    1|t1_d1
    1|t2_d1
    2|t1_d2
    2|t2_d2
    sqlite> select * from(select * from(select * from t1) union select * from(select * from t2 limit 2));
    1|t1_d1
    1|t2_d1
    2|t1_d2
    2|t2_d2
    sqlite> select * from(select * from(select * from t1 limit 2) union select * from(select * from t2));
    1|t1_d1
    1|t2_d1
    2|t1_d2
    2|t2_d2
    sqlite> 

    备注:aHR0cCUzQS8vd3d3LmNuYmxvZ3MuY29tL3poaGQv

  • 相关阅读:
    1.1、MyEclipse自定义注释
    angular2 组件内容嵌入(ng-content)
    常用css初始化样式(淘宝)
    web移动端rem的适配
    PSCC2019常用基础操作
    vs Code打开新的文件会覆盖窗口中的文件?
    关于将ECharts引入到项目中的几种方式
    VS code 设置侧边栏字体大小
    Visual Studio Code(VS code)你们都在用吗?或许你们需要看一下这篇博文
    Angular 监听滚动条事件
  • 原文地址:https://www.cnblogs.com/zhhd/p/7689055.html
Copyright © 2011-2022 走看看