Say I have 5 records in a table.
tableSample(username, color, total)
wendy blue 6
josh yellow 9
brad topaz 3
lily green 4
candy teal 11
now, I wish to select the user with the highest value.
In this case, I want Candy.
Code:SELECT TOP 1 * from tableSample order by total Desc
All good?
now, let's say that 2 or more users share the same top value?
wendy blue 6
josh yellow 9
brad topaz 11
lily green 4
candy teal 11
Would the following be the proper way to display brad and candy?:
Code:DECLARE @highest tinyint SET @highest = (SELECT MAX(total) from tableSample) SELECT * FROM tableSample WHERE total = @highest


Reply With Quote
