sql server - SQL statement to select only row containing max value in one of the columns -


i have following table:

select * [auction].[dbo].[bids] 

enter image description here

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:

enter image description here

... 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 

enter image description here

so, need display 1 row itemid, highestbid, submittedby, , submittedon.

any appreciated!

you can do:

select top 1 * bids itemid = 2 order bidvalue desc 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -