Check this out:
Ruby on Rails “count” method documentation
Can anyone, anywhere, tell me why “: order” would be needed if I am counting something? (Please note, space inserted so that wordpress doesn’t convert it into a smiley).
There are so many other holes and discrepancies in the Rails docs that I won’t try and list them, but this one takes the cake so far.
Advertisements
Maybe if you are grouping at the same time, for example:
ID | User | Colour
– – – – – – – – – –
1 | Fred | Blue
2 | Tom | Red
3 | Jane | Blue
4 | Joe | Green
My sql is rusty, but if I remember correctly
orderby ID, Group by Colour, count of rows = 4,
whereas
Orderby Colour, Group by Colour, count of rows = 3.
the key word ‘distinct’ also comes to mind (I remember spending hours searching a problem to discover that was the word that solved everything)
I could be wrong on all that though, so do double check that
Err, you are wrong about that. “group by” must come first, “order by” orders the final result set (not the set before grouping).