group by query in Codeigniter

0
CodeIgniter- scripts.guru

By using a database class in codeigniter we just need to call group by method. we dont need to write full query. buy using this very easy to do group by on codeigniter

The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.

group by on codeigniter

Let’s create a group_by method in codeigniter

Permits you to write the GROUP BY portion of your query

$this->db->group_by("userid");
// Produces: GROUP BY userid

if you want to do group by multiple column. You can also pass an array of multiple values as well. multiple group by in codeigniter like this

$this->db->group_by(array("userid", "date"));  
// Produces: GROUP BY userid, date