~iany/ Menu
  • Series
  • Tags
  1. Home
  2. Tags
  3. Database

Database

A collection of 1 article

ActiveRecord uniq, count and distinct

ActiveRecord has two methods to remove duplicates. Method uniq and option distinct: true in method count. I thought uniq.count and count(distinct: true) were identical. Indeed, uniq.count still counts duplicates, and count(distinct: true) must be used here. In simple words, use uniq to get unique result set, use count(distinct: true) to count unique result.

Updated Nov 19, 2025  •  1 min read

© 2026  •  ~iany/  •  CC-BY-SA 4.0