I can't seem to get this one right at the moment.
I want distinct records but I need other attributes to come along with the results of the find method. Current nonworking code is:
Visit.find(:all, :select => "user_id, DISTINCT cookie")
I can't seem to get this one right at the moment.
I want distinct records but I need other attributes to come along with the results of the find method. Current nonworking code is:
Visit.find(:all, :select => "user_id, DISTINCT cookie")
you have to write all the columns you need within the :select
Visit.find(:all, :select => "DISTINCT cookie, user_id")
But this will give the unique combination of the cookie and user_id
like
cookie user_id
1 1
1 2
2 1
2 2
But if you want only two cookie i don't think you can do it with Rails find and :select alone. Also if you want though which will come in place of 'x' in above example.
cookie user_id
1 x
2 x