Question: I am working in codeigniter. My problem is i want to show all rows having same id. But when i perform group\_by it only outputs one row of that group.

below is my model

```
function category_content(){
        $this->db->select('*');
        $this->db->from('category');
        $this->db->group_by('category_id');
        $query = $this->db->get();
        return $query->result_array();
    }

```

Please help.

Answer: 
As per the sql properties `Group By` groups all the matching records and will show you only one. It seems you want to sort them by id. Then its better to use `order by`
See the Example hope you will get to know this..

```
    tableA
    _____
    id  name    marks
    --  ----    ---
    1   x       25
    2   y       27
    1   z       30

    SELECT * FROM tableA group by id

OUTPUT:
1   x   25
2   y   27

```

in your case you should use WHERE clause.

```
    SELECT * FROM tableA WHERE id=1

OUTPUT:
1   x   25
1   z   30

    function category_content(){
            $this->db->select('*');
            $this->db->from('category');
            $this->db->where($category_id);
            $query = $this->db->get();
            return $query->result_array();
        }

```

[https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html](http://Group%20By%20:%20MYSQL)