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语句。

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

 

相关文章:

  • 2021-06-15
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案