说明
用于合并两个或多个 SELECT 语句的结果集
示例
Db::field(‘name‘) ->table(‘think_user_0‘) ->union(‘SELECT name FROM think_user_1‘) ->union(‘SELECT name FROM think_user_2‘) ->select();
Db::field(‘name‘) ->table(‘think_user_0‘) ->union(function($query){ $query->field(‘name‘)->table(‘think_user_1‘); }) ->union(function($query){ $query->field(‘name‘)->table(‘think_user_2‘); }) ->select();
Db::field(‘name‘) ->table(‘think_user_0‘) ->union([‘SELECT name FROM think_user_1‘,‘SELECT name FROM think_user_2‘]) ->select();
union all
Db::field(‘name‘) ->table(‘think_user_0‘) ->union(‘SELECT name FROM think_user_1‘,true) ->union(‘SELECT name FROM think_user_2‘,true) ->select();
Db::field(‘name‘) ->table(‘think_user_0‘) ->union([‘SELECT name FROM think_user_1‘,‘SELECT name FROM think_user_2‘],true) ->select();
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1896494
原文地址:http://suyanzhu.blog.51cto.com/8050189/1896494