I have following query:
Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15).uniq
and gives me the error
PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...s"."user_id" WHERE (articles.user_id != 1) ORDER BY Random() L...
When I update the original query to
Article.joins(:themes => [:users]).where(["articles.user_id != ?", current_user.id]).order("Random()").limit(15)#.uniq
so the error is gone... In MySQL .uniq works, in PostgreSQL not. Exist any alternative?
uniq
returns different result? Please show actual SQL queries for each variant (usesql
method). – Kafir.uniq
it returned me also the same row, but with.uniq
always unique row. In PostgreSQL if I use.uniq
, I get the error specified above, if I don't use.uniq
, so the error is gone, but I am getting also the same rows from DB. – Fjord