简体   繁体   中英

Select All Rows, Group By

While using Codeigniter 3, I'm trying to select all records from table "X" while trying to group them by column "Y" as shown below:

$this->db->select();
$this->db->from("X");
$this->db->where(array('is_active' => 1));
$this->db->group_by('Y');

However, this retrieves only one record for each group.... any help would be great! Thanks!

Use the following pattern :

    $this->db->select('*');
    $this->db->from('X');
    $this->db->where('is_active', 1);
    $this->db->group_by('Y');
    $query_result = $this->db->get();
    $result = $query_result->result();
    return $result;

使用$ this-> db-> get()-> result_array()并将其分配给变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM