I'm trying to developed some sort of ticket system, but I'm having trouble with a small part.
So, we have discussions, stored in the "discussions" table which are order by UNIX timestamp column "created_at"
Then, I have "comments" table, which has the tickets responses.
What I want to do is order the tickets by the recent activity basically.
I'm not that good at joining tables in queries, this is what I tried but it doesn't work sadly: /
SELECT *
FROM (`discussions`)
JOIN `comments` ON `comments`.`object_id` = `discussions`.`id`
WHERE `project_id` = '2'
AND `comments`.`type` = 'discussion'
ORDER BY `comments`.`created_at` ASC,
`discussions`.`created_at` DESC
I'm using CodeIgniter and this is the Active Record code
$query = $this->db->where('project_id', $id)
->join('comments', 'comments.object_id = discussions.id')
->where('comments.type', 'discussion')
->order_by('comments.created_at', 'asc')
->order_by('discussions.created_at', 'desc')
->get('discussions');
Thanks a lot for the help!