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 8022581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:18:16+00:00 2026-06-04T22:18:16+00:00

I need to fetch like the winner bids, and a bid can be for

  • 0

I need to fetch like the winner bids, and a bid can be for a different date (don’t ask why), so I need to select the bid with minimum bid price for each day.

Here are my models

Leilao
  has_many :bids

Bid
  belongs_to :leilao
  #winner_name
  #price
  #date

I tried a solution already and got close to what I need. The problem is that, in some cases, when I create a new bid with lower price, I don’t know why the results do not change.

Leilao.find(1).bids.having('MIN("bids"."price")').group('date').all

This seems to work, but as I said, it does not work in some cases when I create a new bid. But it worked properly once. So, if you do know what might be happening, please tell me.

I then searched for some way for doing this and I got the following

Leilao.find(1).bids.minimum(:price, :group => :date)

which works properly, but with this, I just fetch the dates and prices and I need all the bid data.

I could get it by doing this, but it feels really bad to me

winner_bids = Leilao.find(1).bids.minimum(:price, :group => :date)
winners_data = []
winner_bids.each do |date, price|
  winners_data << Leilao.find(1).bids.where(price: price, date: date).first
end
winners_data

Any idea a better way to do this? Or what’s wrong with my first approach?

Performance is not an issue, since this is just for academic propose but it just feels nasty for me

Also those Leilao.find(1) is just for explaining it here, I’m not using it allover the place, no.

Thanks in advance

  • 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-04T22:18:17+00:00Added an answer on June 4, 2026 at 10:18 pm

    see this

    mysql> select * from bids;
    +----+-------------+-------+------------+-----------+
    | id | winner_name | price | date       | leilao_id |
    +----+-------------+-------+------------+-----------+
    |  1 | A           |   1.1 | 2012-06-01 |         1 |
    |  2 | A           |   2.2 | 2012-06-01 |         1 |
    |  3 | A           |   3.3 | 2012-05-31 |         1 |
    |  4 | A           |   4.4 | 2012-05-31 |         1 |
    +----+-------------+-------+------------+-----------+
    4 rows in set (0.00 sec)
    
    mysql> select * from bids where leilao_id = 1 group by date order by price asc;
    +----+-------------+-------+------------+-----------+
    | id | winner_name | price | date       | leilao_id |
    +----+-------------+-------+------------+-----------+
    |  1 | A           |   1.1 | 2012-06-01 |         1 |
    |  3 | A           |   3.3 | 2012-05-31 |         1 |
    +----+-------------+-------+------------+-----------+
    2 rows in set (0.00 sec)
    

    in rails

    1.9.2-p290 :013 > Leilao.find(1).bids.order(:price).group(:date).all
    [
        [0] #<Bid:0x00000003553838> {
                     :id => 1,
            :winner_name => "A",
                  :price => 1.1,
                   :date => Fri, 01 Jun 2012,
              :leilao_id => 1
        },
        [1] #<Bid:0x00000003553518> {
                     :id => 3,
            :winner_name => "A",
                  :price => 3.3,
                   :date => Thu, 31 May 2012,
              :leilao_id => 1
        }
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fetch only first record (because I need last date) of resultset,
Im using vb.net and I need to fetch data from two different tables and
I have a small requirement like . i need to fetch all record from
I have a string that looks like: >ANY CONTENT</span>(<a id=show I need to fetch
I need to fetch the parent Subjects using Javascript. How can I get all
For some reason I need to fetch emails from /var/mail/username file. It seems like
Using garb (http://github.com/vigetlabs/garb) i need to fetch the same Map Overlay XML, like Google
This is an example URL. http://stackoverflow.com/questions/ask?a=1&b=2 question : I need to fetch path name
Edit: Looks like I typoed today. Thanks, Antoine. I need to fetch the published
I need to fetch the records based on a 'like' match against a set

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.