Code igniter active record query:
$this->blog_db->select('a.tytul, a.data_dodania, b.post_id, COUNT(b.post_id) as liczba')
->from('posts a')
->join('komentarze b', 'a.id=b.post_id')
->group_by('b.post_id')
->order_by('liczba', 'desc')
->limit(5)
->get('posts');
It gives me result of count query multiplyed by number of posts but it should work like this: custom mysql query Using the same query as custom query in codeigniter works like a charm
$this->blog_db->query('SELECT a.tytul, b.post_id, a.data_dodania, COUNT(b.post_id) as liczba
FROM posts a
JOIN komentarze b ON a.id=b.post_id
GROUP BY b.post_id
ORDER BY liczba desc
LIMIT 0, 5
');
What I have did wrong on active record query?