the easiest way
$user = $this->Users->find('all',[
'fields' => array('amount' => 'MAX(Users.id)'),
]);
using select instead of parameter array
$user = $this->Users->find()
->select(['amount' => 'MAX(Users.id)']);
using SQL functions for a cake
$query = $this->Users->find();
$user = $query
->select(['amount' => $query->func()->max('Users.id')]);
the above three give the same results
if you want to have one entry, you must call ->first()in the request object:
$user = $user->first();
$amount = $user->amount;
source
share