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

  • SEARCH
  • Home
  • 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 8356801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:17:24+00:00 2026-06-09T10:17:24+00:00

Im currently trying to pull some data into a table but i only want

  • 0

Im currently trying to pull some data into a table but i only want to show a certain row if it contains the highest amount in a column.

+----+--------+---------+---------+----------+-----+
| id | auc_id | user_id | bamount |   date   | out | 
+----+--------+---------+---------+----------+-----+
| 20 | 10002  |  10008  |    12   |1342445619|   1 |
| 21 | 10002  |  10009  |    14   |1342445667|   1 |
| 22 | 10002  |  10008  |    16   |1342445669|   0 |
+----+--------+---------+---------+----------+-----+

I would like to show in the table the most recent row for each user_id for each auc_id

so user for auc_id 10002 user 10008 would show the bamount of 16 only in the table and ignore the bamount of 12 row because 12 is smaller than 16

Is this possible?

  • 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-09T10:17:25+00:00Added an answer on June 9, 2026 at 10:17 am

    Yes, it’s possible to show the row that corresponds to each user’s maximum bid.

    Start by doing what @Bryan Moyles suggested; summarize your bids by user.

     SELECT user_id, MAX(bamount) bamount
       FROM table_name
      GROUP BY user_id
    

    Now you know each user’s biggest bid. Next you need to retrieve the whole row, by joining your original table to the summary.

     SELECT t.id, t.auc_id, t.user_id, t.bamount, t.date, t.out
       FROM table_name t
      INNER JOIN (
         SELECT user_id, MAX(bamount) bamount
           FROM table_name
          GROUP BY user_id
      ) m ON t.user_id = m.user_id AND t.bamount = m.bamount
    

    This is almost correct. But if you have a user who has bid precisely the same amount on two different auctions, you’ll get two rows for that user. Your question didn’t specify what you need to do with this particular edge case.

    How about this? Let’s give the most recent (that is, the one with the largest numerical id) bid for the user in the case where two bid amounts are identical. So, we need another summary query, like so.

     SELECT w.user_id, MAX(w.id) id
       FROM table_name w
      INNER JOIN (
         SELECT user_id, MAX(bamount) bamount
           FROM table_name
          GROUP BY user_id
      ) x ON w.user_id = x.user_id AND w.bamount = x.bamount
      GROUP BY w.user_id
    

    Now you join that query to your raw table, and, lo and behold, you’re done. Don’t forget to use an appropriate ORDER BY clause in this overall query.

    This presumes that id is a primary key unique column.

     SELECT t.id, t.auc_id, t.user_id, t.bamount, t.date, t.out
       FROM table_name t
      INNER JOIN (
         SELECT w.user_id, MAX(w.id) id
           FROM table_name w
          INNER JOIN (
             SELECT user_id, MAX(bamount) bamount
               FROM table_name
              GROUP BY user_id
          ) x ON w.user_id = x.user_id AND w.bamount = x.bamount
         GROUP BY w.user_id
      ) m ON t.id = m.id
    

    See how that goes? There’s a summary finding the largest numeric bid for user. It’s nested into a summary that finds the largest id number for each user. It, in turn is used to select the rows you need from your raw table.

    There may be easier ways to pull this off by taking advantage of a better understanding of your data than you’ve given in your question. For example, if you know bids always increase, and no two bids have the same date, and you don’t care about getting the right auction if a user is bidding on more than one, then you may be able to just summarize by the date field. But, in my experience, it’s better to avoid reliance on assumptions about your data (such as bids always increasing) because things get goofed up in real life.

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

Sidebar

Related Questions

I'm trying to stick some data into the app so I can then build
I want to pull data from table Province_Notifiers and also fetch all corresponding items
I'm trying to parse some XML data to get the value of a certain
I am trying to pull up some data. Here is the setup: A [school]
So I'm trying to pull some data from two text files. The first loads
I'm trying to pull some data out of an OLD database that is running
I am trying to pull a value (only) from some XML in Python using
I'm currently trying to pull data from a database using a variable and then
Im currently trying to downlaod a audio track from a WCF, i need some
Im currently trying to learn some stuff about encryption, it's algorithms and how it

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.