As I mentioned here , in Rails 4 using (...).uniq.count(:user_id) , as mentioned in other answers (for this question and elsewhere on SO), will actually lead to an additional DISTINCT found in the request:
SELECT DISTINCT COUNT(DISTINCT user_id) FROM ...
We really need to use the SQL string:
(...).count("DISTINCT user_id")
What gives us:
SELECT COUNT(DISTINCT user_id) FROM ...
JacobEvelyn 12 Oct '15 at 20:04 2015-10-12 20:04
source share