Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all columns of each distinct records in rails

I want to get distinct records in rails. For that I see this Rails: how can I get unique values from column

But the issue is that by this solution I only get the Ids .

ViewsLog.uniq.pluck(:unit_id)
[24, 21, 23, 4, 16, 5, 7]

I want all columns of uniq unit_id

like image 467
Haseeb Ahmad Avatar asked Dec 10 '22 19:12

Haseeb Ahmad


1 Answers

You can use group; it gives you all distinct records:

 ViewsLog.group(:unit_id)
like image 191
Vishal JAIN Avatar answered Dec 29 '22 20:12

Vishal JAIN