I have a query that looks like this:
Person.where.not(first_name: nil).where.not("lower(first_name) = ?", 'mike').order('RANDOM()').limit(6).pluck("distinct(lower(first_name))")
It returns me the following error when I try to run it:
ActiveRecord::StatementInvalid: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...AND (NOT (lower(first_name) = 'mike')) ORDER BY RANDOM() L...
How can I solve this problem?
Person.where.not(first_name: nil).where.not("lower(first_name) = ?", 'mike').order('RANDOM()').limit(6).pluck("lower(first_name)").uniqorPerson.where('first_name IS NOT NULL and lower(first_name) != ?', 'mike').order('RANDOM()').limit(6).pluck("lower(first_name)").uniq