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
- For
product_namecolumn: if multiple records with the sameproduct_nameare registered, the latest id value should be displayed. - For
added_datecolumn: multiple records with the sameadded_dateare 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();