如何在codeigniter中写联合?

时间:2016-10-07 11:53:37

标签: php codeigniter

select ID,Name_of_Movie as Name_of_Moviee 
from moviestable 
UNION 
select ID,New_Name 
from moviestable

我在codeigniter中需要这个查询..

1 个答案:

答案 0 :(得分:2)

  

UNION 首先出现在

下面
$data['values']=$this->db->query(
'select ID,Name_of_Movie as Name_of_Moviee from moviestable       
 UNION  
select ID,New_Name from moviestable')->get()->result_array();
  

中对UNION的第二种方式
$this->db->select("ID,Name_of_Movie as Name_of_Moviee");
$this->db->from("moviestable");
$query1 = $this->db->get_compiled_select(); // It resets the query just like a get()

$this->db->select("ID,New_Name");
$this->db->distinct();
$this->db->from("moviestable");
$query2 = $this->db->get_compiled_select(); 

$data['values'] = $this->db->query($query1." UNION ".$query2)->result();

您为查询实施任何一个