UNION操作用于合并两个或多个 SELECT 语句的结果集。

    使用示例:

    1. Db::field('name')
    2. ->table('think_user_0')
    3. ->union('SELECT name FROM think_user_1')
    4. ->union('SELECT name FROM think_user_2')
    5. ->select();

    闭包用法:

    1. Db::field('name')
    2. ->table('think_user_0')
    3. ->union(function($query){
    4. $query->field('name')->table('think_user_1');
    5. })
    6. ->union(function($query){
    7. $query->field('name')->table('think_user_2');
    8. })
    9. ->select();

    或者

    1. Db::field('name')
    2. ->table('think_user_0')
    3. ->union(['SELECT name FROM think_user_1','SELECT name FROM think_user_2'])
    4. ->select();

    支持UNION ALL 操作,例如:

    1. Db::field('name')
    2. ->table('think_user_0')
    3. ->union('SELECT name FROM think_user_1',true)
    4. ->union('SELECT name FROM think_user_2',true)
    5. ->select();

    或者

    1. Db::field('name')
    2. ->table('think_user_0')
    3. ->union(['SELECT name FROM think_user_1','SELECT name FROM think_user_2'],true)
    4. ->select();

    每个union方法相当于一个独立的SELECT语句。

    注意:UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。