I want to display product information by grouping them as one in cakephp

49 Views Asked by At

I have a product table with id, product_name and added_date. I want to display product_name and added_date but I have the following condition to display the results

  1. For product_name column: if multiple records with the same product_name are registered, the latest id value should be displayed.
  2. For added_date column: multiple records with the same added_date are registered, the latest id value should be displayed.

I tried the following but it didnot gave result as exprected:

$products = $this->Products->find()
            ->group([
                'Products.product_name',
                'Products.added_date',
                ])
            ->order([
                'Product.added_date DESC',
                'Product.id DESC'
            ])
            ->all();
0

There are 0 best solutions below