MySQL Query: Winning Auction Bid

Posted by mabwi on Stack Overflow See other posts from Stack Overflow or by mabwi
Published on 2010-06-05T15:25:00Z Indexed on 2010/06/05 15:32 UTC
Read the original article Hit count: 267

Filed under:
|

I have a small Bidding system that I'm using for a fantasy auction draft. I'm trying to use the below query to pull up the max bids on each player. However, it's not actually giving me the max bid, it's just giving me the first one entered in to the database.

SELECT Bid.id FROM bids AS Bid 
WHERE Bid.active =1
GROUP BY player_id HAVING MAX( Bid.amount )

Here's the Bid table layout, in case it helps:

CREATE TABLE IF NOT EXISTS `bids` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `player_id` int(10) NOT NULL,
  `amount` int(6) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `winning_bid` int(1) NOT NULL DEFAULT '0',
  `active` int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql