Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:04:16+00:00 2026-06-12T05:04:16+00:00

ActionView::Template::Error (PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

  • 0

ActionView::Template::Error (PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

I’m creating an events website and I’m trying to sort the rendered rsvps by the start time of the event. There are a lot of RSVPS so I’m grouping them with distinct, but I’ve been having a lot of difficulty over the last few days on sorting the results without this error popping up on PG. I’ve looked at some of the previous questions on the topic and am still pretty lost. How can I get this to work? Thank you so much!

@rsvps = Rsvp.where(:voter_id => current_user.following.collect {|f| f["id"]}, :status => 'going').where("start_time > ? AND start_time < ?", Time.now, Time.now + 1.month).order("count_all desc").count(:group => :event_id).collect { |f| f[0] }

<%= render :partial => 'rsvps/rsvp', :collection => Rsvp.where(:event_id => @rsvps).select("DISTINCT(event_id)").order('start_time asc') %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:04:17+00:00Added an answer on June 12, 2026 at 5:04 am

    The ORDER BY clause can only be applied after the DISTINCT has been applied. Since only the fields in the SELECT statement are taken into consideration for the DISTINCT operations, those are the only fields may be used in the ORDER BY.

    Logically, if you just want a distinct list of event_id values, what order they occur in should be irrelevant. If order does matter, then you should add the start_time to the SELECT list so that there is context for the order.

    Also, these two SELECT clauses are NOT equivalent, so be careful:

    SELECT DISTINCT(event_id, start_time) FROM ...
    
    SELECT DISTINCT event_id, start_time FROM ...
    

    The second is the form you want. The first will return a series of records with the data represented as a ROW construct (a single column with a tuple inside). The second will return normal columns of data output. It only works as expected in the single-column case where the ROW construct is reduced down since it is only a single column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Copied from my log file ActionView::Template::Error (Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs
ActionView::Template::Error (HandleScope::HandleScope: Entering the V8 API without proper locking in place (in /app/app/assets/javascripts/application.js)): 3:
I am not experiencing errors locally but am on Heroku. Error is: 'ActionView::Template::Error (undefined
I have an application running on Heroku that, on occasion, reports Timeout::Error and (ActionView::Template::Error)
Thanks for helping. The errors occurs during implementation accepts_nested_attributes_for . I get ActionView::Template:Error (undefined
This is the error: ActionView::Template::Error (No route matches {:action=>send_to_client, :controller=>stages}): app/views/stages/_show.html.erb:13:in `_app_views_stages__show_html_erb__3606907191157577988_2203521120_617355097038007272' app/controllers/stages_controller.rb:78:in `block
I get this error: ActionView::Template::Error (no implicit conversion to float from nil): Around this
I'm getting this strange error using Rails 3.0.2. ActionView::Template::Error (undefined method `parent' for nil:NilClass):
what i'm trying to do is change the list of available for select localities,
Here's the error I get: ActionView::Template::Error (You have a nil object when you didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.