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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:34:08+00:00 2026-05-21T07:34:08+00:00

I have two tables with a many to one relationship which represent lots and

  • 0

I have two tables with a many to one relationship which represent lots and bids within an auction system. Each lot can have zero or more bids associated with it. Each bid is associated with exactly one lot.

My table structure (with irrelevant fields removed) looks something like this:

table structure

For one type of auction the winning bid is the lowest unique bid for a given lot.

E.g. if there are four bids for a given lot: [1, 1, 2, 4] the lowest unique bid is 2 (not 1).

So far I have been able to construct a query which will find the lowest unique bid for a single specific lot (assuming the lot ID is 123):

SELECT id, value FROM bid
WHERE lot = 123 
AND amount = (
    SELECT value FROM bid 
    WHERE lot = 123
    GROUP BY value HAVING COUNT(*) = 1 
    ORDER BY value
)

This works as I would expect (although I’m not sure it’s the most graceful approach).

I would now like to construct a query which will get the lowest unique bids for all lots at once. Essentially I want to perform a JOIN on the two tables where one column is the result of something similar to the above query. I’m at a loss as to how to use the same approach for finding the lowest unique bid in a JOIN though.

Am I on the wrong track with this approach to finding the lowest unique bid? Is there another way I can achieve the same result?

Can anyone help me expand this query into a JOIN?

Is this even possible in SQL or will I have to do it in my application proper?

Thanks in advance.

(I am using SQLite 3.5.9 as found in Android 2.1)

  • 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-05-21T07:34:09+00:00Added an answer on May 21, 2026 at 7:34 am

    You can use group by with a “having” condition to find the set of bids without duplicate amounts for each lot.

              select lotname, amt
              from lot inner join bid on lot.id = bid.lotid
              group by lotname, amt having count(*) = 1
    

    You can in turn make that query an inline view and select the lowest bid from it for each lot.

    select lotname, min(amt)
    from
    (
      select lotname, amt
              from lot inner join bid on lot.id = bid.lotid
              group by lotname, amt having count(*) = 1
    ) as X
    
    group by X.lotname
    

    EDIT: Here’s how to get the bid id using this approach, using nested inline views:

     select bid.id as WinningBidId, Y.lotname,  bid.amt
    from
    bid
    join
    (   
       select x.lotid, lotname, min(amt) as TheMinAmt
    from
    (
        select lot.id as lotid, lotname,  amt 
        from lot inner  join bid   on lot.id = bid.lotid
        group by lot.id, lotname, amt
        having count(*)=1 
    ) as X
    
    group by x.lotid, x.lotname
    ) as Y
    on Y.lotid = bid.lotid and Y.TheMinAmt = Bid.amt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.