Active Record 'count_all_results' ignores 'distinct' clause #59

bitbucket-import opened this Issue Aug 19, 2011 · 8 comments


None yet
4 participants

When calling $this->db->count_all_result('table'), active record replaces the SELECT portion with 'COUNT(*) AS numrows', so 'DISTINCT' clause is overriden, returning incorrect number of rows.

Maybe it is possible to modify the distinct() method to accept parameters (e.g. same as with select())?

narfbg added a commit that referenced this issue Oct 26, 2012


narfbg commented Oct 26, 2012


@narfbg narfbg closed this Oct 26, 2012

Is it even possible to modify the distinct() method so you get() only these fields, like:


would result in:

SELECT DISTINCT "name" FROM "my_table"

instead of:


narfbg commented Oct 26, 2012


Cool, didn't know that, thanks :)

nonchip pushed a commit to nonchip/CodeIgniter that referenced this issue Jun 29, 2013

Huji commented Jul 31, 2013

This issue still happens in version 2.1.3 and that is what I explained in #2572 (sorry for opening a new bug, my bad). Please reopen this issue.


narfbg commented Aug 1, 2013

I'm not (re)opening issues that have already been resolved. The fix is included in the develop branch, which will be released as CI 3.0.

Huji commented Aug 1, 2013

Apologies. There was no way for me to know which version of CI will include this fix. Perhaps update this bug and set Milestone to version 3.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment