-4

So I have a table for biddings, you can win the bidding by posting the lowest unique bid. So if 2 people place a bet of $1, none of them win, if 1 person places a bet of $2, this guy wins. But how can I check this in MySQL?

hgb123
  • 13,869
  • 3
  • 20
  • 38
  • 4
    Welcome to Stack Overflow! You seem to be asking for someone to write some code for you. Stack Overflow is a question and answer site, not a code-writing service. Please [see here](http://stackoverflow.com/help/how-to-ask) to learn how to write effective questions. Maybe add some example – Alberto Moro Dec 11 '18 at 10:36
  • errr https://www.ebay.com ? – Martin Dec 11 '18 at 10:43
  • It's for a school task, I tried to search it myself, but I couldn't find some an answer of possibility. I was thinking to put it in a for loop in my php to find the unique value, but I was wondering if there was a solution in mySQL. DISTINCT() doesn't work on this. – Hannes De Baere Dec 11 '18 at 10:43
  • See here: https://stackoverflow.com/questions/426731/min-max-vs-order-by-and-limit – Martin Dec 11 '18 at 10:44
  • I find it hard to believe you've tried looking for yourself. I copy/pasted and googled the title of your question and came up with multiple answers on Stackoverflow in under 60 seconds. – Martin Dec 11 '18 at 10:45
  • 2
    Maybe it's just a `GROUP BY bet` with a `HAVING COUNT(*) = 1` and `ORDER BY bet ASC LIMIT 1`. Then get the `MAX(bidder)` from that. – LukStorms Dec 11 '18 at 10:49

1 Answers1

0

Assume your table has the bid value stored in the field name bet, then below is a worked solution:

SELECT * FROM YourTableName
WHERE bet = (SELECT MIN(bet) FROM YourTableName)
GROUP BY bet
HAVING COUNT(*) = 1;
hgb123
  • 13,869
  • 3
  • 20
  • 38
  • 1
    you should **always** explain your code to help OP understand the issue and solution to help develop their skillset :) – treyBake Dec 11 '18 at 11:40
  • So I found the correct solution, thanks for the feedback! Ass you can see, I have two tables, one with the auctions, one with the biddings `SELECT auction.auction_id, bid.price, bid.auction_id, auction.* FROM auction INNER JOIN bid on auction.auction_id = bid.auction_id WHERE auction.auction_id = 2 GROUP BY bid.price HAVING COUNT(bid.price)<2 ORDER BY price ASC limit 1` – Hannes De Baere Dec 12 '18 at 13:20