Imported From: http://groups.google.com/group/in-portal-bugs/browse_thread/thread/4635504373ca3d86#
There's bug with kDBList::getCountSQL method, which generates SQL for
counting list totals. It checks if there's DISTINCT in SQL and, if it's
there, tries to replace it for COUNT(DISTINCT ...) construction instead of
simple COUNT(*). Problem is that it checks for distinct in ANY place of
query, but replaces it in beginning, so, if there's DISTINCT in subquery, it
won't replace anything. So, count SQL will be equal to list SQL, and you
will get first record's first field's value (according to
kDBConnection::GetOne logic) as record count.
I attached patch that fixes it. Also, it now checks for ANY whitespaces
between SELECT and DISTINCT instead of one space.