Find rows with multiple duplicate fields with Active Record, Rails & Postgres

ids = TabLesson.select("MIN(id) as id").group(:lesson_id, :tab_id).collect(&:id)

records = TabLesson.where.not(id: ids)

Comments