我正在尝试在 codeigniter 中执行联合。我在其他地方找到了这个代码骨架:
$this->db->select('title, content, date');
$this->db->from('mytable');
$query = $this->db->get();
$subQuery1 = $this->db->_compile_select();
$this->db->_reset_select();
// #2 SubQueries no.2 -------------------------------------------
$this->db->select('title, content, date');
$this->db->from('mytable2');
$query = $this->db->get();
$subQuery2 = $this->db->_compile_select();
$this->db->_reset_select();
// #3 Union with Simple Manual Queries --------------------------
$this->db->query("select * from ($subQuery1 UNION $subQuery2) as unionTable");
// #3 (alternative) Union with another Active Record ------------
$this->db->from("($subQuery1 UNION $subQuery2)");
$this->db->get();
让我感到困惑的是,您在原始子查询中有一个 get_where 子句,您如何包含它?像这样的东西:
查询 1
$this->db->select('Id,title, content, date');
$this->db->from('mytable');
$query = $this->db->get_where('Boo', array('Id' => $foo['foo_Id']);
$subQuery1 = $this->db->_compile_select();
查询 2
$this->db->select('title, content, date');
$this->db->from('mytable2');
$query = $this->db->get_where('Boo', array('Title' => $foo['foo_Title'])
$subQuery2 = $this->db->_compile_select();
谢谢你。