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

大理石平台价格

使用示例:

  1. $Model->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. $Model->field('name')
  2. ->table('think_user_0')
  3. ->union(array('field'=>'name','table'=>'think_user_1'))
  4. ->union(array('field'=>'name','table'=>'think_user_2'))
  5. ->select();

或者

  1. $Model->field('name')
  2. ->table('think_user_0')
  3. ->union(array('SELECT name FROM think_user_1','SELECT name FROM think_user_2'))
  4. ->select();

支持UNION ALL 操作,例如:

  1. $Model->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. $Model->field('name')
  2. ->table('think_user_0')
  3. ->union(array('SELECT name FROM think_user_1','SELECT name FROM think_user_2'),true)
  4. ->select();

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

 
01-08 11:10