[thelist] Quick SQL Help Please

Timothy Joko-Veltman tim at indigopixel.com
Thu Oct 28 09:04:52 CDT 2004


On Thu, 2004-10-28 at 08:49 -0500, Rob Smith wrote:
> Hi,
> 
> Assume this table:
> 
> Bid 		ID		By
> 3		2		John
> 52		1		Jane
> 3		3		Jim
> 15		1		Josh
> 6		3		James
> 2		2		Jimmy
> 45		1		Joan
> 2		3		Jack
> 
> How do I get the max bids per item showing the correct winning bidder?
> 
> The correct Results should be:
> 
> 52		1		Jane
> 3		2		John
> 6		3		James
> 
> I thought it would be something like:
> 
> SELECT MAX(LatestBid) AS LatestBid, TBayBidID, MAX(Bidder) AS Bidder FROM
> TBayBid GROUP BY TBayBidID Order by TBayBidID
> 
> but that's not right,
> 
> Rob Smith

Assuming the column names listed above and the name of that table is
"TBayBid", this should do the trick ... (I added a table alias for
clarity.)

SELECT MAX(t.Bid) AS LatestBid, t.ID, t.By FROM `TBayBid` t
GROUP BY t.ID ORDER BY t.ID

Regards,

Tim

-- 
"The resonable man adapts himself to the world; the unresonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man."    --George Bernard Shaw



More information about the thelist mailing list