Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Discussion on Group By in Cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 586
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss Group By in Cakephp

    In Cakephp web application sometimes we need to fetch data from database according to group field name. So GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

    Note:- GROUP BY statement works as a string, So we have to separate multiple group by fields by a comma.

    We can see below example for better understanding and also we can see the possible keys that we will use in CakePHP query.

        $query =
        'conditions' => array('Model.field' => $thisValue), //conditions array of
        'recursive' => 1, //int
        //array of field names
        'fields' => array('Model.field1', 'DISTINCT Model.field2'),
        //string or array defining order
        'order' => array('Model.created', 'Model.field3 DESC'),
        'group' => array('Model.field'), // here use fields to GROUP BY
        'joins' => array('Join relations here'), // for ex: LEFT JOIN `entities` AS Entity ON `Entity`.`category_id` = `Category`.`id`
        'limit' => n, //int
        'page' => n, //int
        'offset' => n, //int
        'callbacks' => true //other possible values are false, 'before', 'after'

    I hope this blog will help you.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: