2014.04.26
codeigniterでselect文にunionを使いたい


Subquery.php
Subquery.phpをapplication/libraries フォルダにおきます。以下のように実装することでunionのselect文(select name,description from table_a union select name,description from table_b)が実行できます。$this->load->library("subquery"); $sub1 = $this->subquery->start_union(); $sub1->select(array("name", "description")); $sub1->from("table_a"); $sub2 = $this->subquery->start_union(); $sub2->select(array("name", "description")); $sub2->from("table_b"); $this->subquery->end_union(); $query = $this->db->get();