Answer the question
In order to leave comments, you need to log in
How to pull last row in query with group by?
Hello sql-guru
has already broken his brain and fingers on the keyboard, but I can’t get the last entry from the array
, there is such a funka:
function get_all_threads_list($user_id, $order_by = 'DESC')
{
$sql = 'SELECT m.*, s.status, t.subject, ' . USER_TABLE_USERNAME .
' FROM ' . $this->db->dbprefix . 'msg_participants p ' .
' JOIN ' . $this->db->dbprefix . 'msg_threads t ON (t.id = p.thread_id) ' .
' JOIN ' . $this->db->dbprefix . 'msg_messages m ON (m.thread_id = t.id) ' .
' JOIN ' . $this->db->dbprefix . USER_TABLE_TABLENAME . ' ON (' . USER_TABLE_ID . ' = m.sender_id) '.
' JOIN ' . $this->db->dbprefix . 'msg_status s ON (s.message_id = m.id AND s.user_id = ? ) ' .
' WHERE p.user_id = ? group by m.thread_id ORDER BY t.id ' . $order_by. ', m.cdate '. $order_by;
$query = $this->db->query($sql, array($user_id, $user_id));
return $query->result_array();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question