sql server - SQL statement to select only row containing max value in one of the columns -
i have following table:
select * [auction].[dbo].[bids]
i need select row highest bidvalue. when
select bids.itemid, max(bids.[bidvalue]) highestbid [auction].[dbo].[bids] bids bids.itemid = 2 group bids.itemid
i right row:
... when add 2 other fields doesn't work (i know shows 3 rows because of group by, throws error if don't include fields in group by):
select bids.itemid, max(bids.[bidvalue]) highestbid, bids.submittedby, bids.submittedon [auction].[dbo].[bids] bids bids.itemid = 2 group bids.itemid, bids.submittedby, bids.submittedon
so, need display 1 row itemid, highestbid, submittedby, , submittedon.
any appreciated!
you can do:
select top 1 * bids itemid = 2 order bidvalue desc
Comments
Post a Comment