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

I need this query in codeigniter..

Alok Patel
  • 7,842
  • 5
  • 31
  • 47
sai vamshi
  • 25
  • 1
  • 5

1 Answers1

2

there are two way for UNION first in below

$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();

Second way to UNION in

$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();

You are implement any one for your query

kuldeep
  • 218
  • 1
  • 10
  • Dear Your answer like a comment. please explain it and correct the syntax.. Its very important for stackoverflow guys. – Kumar Rakesh Oct 07 '16 at 12:20