I have two tables : user
and payment
.
The user
table have 3 records
and each has 2 payment records
in payment
table. I want the last payment details of the users, but instead of getting 3 rows, I get only 1 row.
$this->db->select('user.*, max(payment.create_at) as last_payment_at');
$this->db->from('user');
$this->db->join('payment','payment.user_id=user.id', 'left');
$this->db->order_by("user.id", "desc");
return $this->db->get()->result_object();