MySQL Query: Winning Auction Bid
- by mabwi
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 ;