我正在嘗試在codeigniter中執行聯合。我發現在別處這個代碼骨架:Union Activerecord 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();
謝謝。
我讀過,做這樣的說法是不這樣做 – bobo2000 2012-04-05 14:06:35
這是簡單明瞭的方式來做到這一點的最好辦法。你能分享一下你讀過的東西嗎? – 2012-04-05 14:16:26
當然,這裏閱讀:[鏈接] http://stackoverflow.com/questions/2040655/union-query-with-codeigniters-active-record-pattern [/ link] – bobo2000 2012-04-05 14:18:31