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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:38:15+00:00 2026-06-16T12:38:15+00:00

I’m trying to write a query that will find all rows in a group

  • 0

I’m trying to write a query that will find all rows in a group EXCEPT the row with the max value. I have a query so far that finds the row with the max value, but now I need to find all the rest of the rows. Here is a SQLFiddle with the two databases and sample data. I also have the query that finds the max rows.
http://sqlfiddle.com/#!2/514d2/33

For those that don’t want to use SQLFiddle…
Tablename: listings
Tablename: bids

SELECT listings.end_date, listings.user_id, listings.title, 
  listings.auc_fp, listings.id, listings.auc_image1
FROM listings 
JOIN bids b1 
ON b1.listing_id=listings.id 
LEFT JOIN bids b2 
ON b2.listing_id=listings.id AND b1.bid < b2.bid
WHERE b1.user_id = 1
AND b2.bid IS NULL
AND listings.end_date > NOW()
ORDER BY listings.list_ts DESC

Above is the query that find the max rows. I’m trying to join the listings table with the bids table on listings.id=bids.listing_id. Then I need to find all the rows where a user ($user or user “1”) has bid on that listing. Then I need to exclude the listings where the user is has the max bid (which is what the query above does).

I originally thought I could use the query above as a subquery to exclude the listings where the user is the max bidder. But I’m not sure if that’s the best way to do it and I’m not that good with subqueries.

  • 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-16T12:38:16+00:00Added an answer on June 16, 2026 at 12:38 pm

    Note that answer was revised several times based on the comments below.

    SELECT
        lst.end_date,
        lst.title,
        lst.auc_fp,
        lst.id as listing_id,
        lst.auc_image1,
        b.user_id as bid_user_id,
        b.bid as bid_amount,
        maxbids.maxbid as maxbid_for_listing
    FROM listings lst
    INNER JOIN
    (
        SELECT listing_id, MAX(bid) maxbid
        FROM bids b
        GROUP BY listing_id
    ) maxbids ON lst.id = maxbids.listing_id
    INNER JOIN bids maxusers ON maxusers.bid = maxbids.maxbid AND maxusers.listing_id = maxbids.listing_id
    INNER JOIN bids b ON
        maxbids.listing_id = b.listing_Id AND
        b.bid < maxbids.maxbid AND
        b.user_id <> maxusers.user_id
    WHERE lst.end_date > NOW()
    ORDER BY lst.list_ts DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.