Write union query in codeigniter style

前端 未结 3 1261
余生分开走
余生分开走 2020-12-11 11:28

How can I write the following query in Codeigniter style.

SELECT COUNT(`id`) AS reccount
  FROM 
    (SELECT `id` FROM table1 
     WHERE tid= \'101\' AND `s         


        
3条回答
  •  长情又很酷
    2020-12-11 12:11

    function get_merged_result($ids){                   
        $this->db->select("column");
        $this->db->distinct();
        $this->db->from("table_name");
        $this->db->where_in("id",$model_ids);
        $this->db->get(); 
        $query1 = $this->db->last_query();
    
        $this->db->select("column2 as column");
        $this->db->distinct();
        $this->db->from("table_name");
        $this->db->where_in("id",$model_ids);
    
        $this->db->get(); 
        $query2 =  $this->db->last_query();
        $query = $this->db->query($query1." UNION ".$query2);
    
        return $query->result();
    }
    

提交回复
热议问题