Postgres MySQL SQLite , GROUP BY. , . , .
id name
1 foo
2 bar
2 baz
GROUP BY id. MySQL , , . .
id name
1 foo
2 bar
Postgres . , . , , , . , , , , min() max() . :select => 'min(comments.id), min(comments.some_other_column)', , user_id. : group = > 'user_id' .
Btw, min() max() , , . - , google " postgres first", postgres. mysql sqlite.
, , .
unique_comments = []
Comment.recent.each do |comment|
unless unique_comments.find{|c| c.user_id == comment.user_id}
unique_comments << comment
end
break if unique_comments.size > 2
end
3 .