user3304614
user3304614

Reputation: 169

Selecting three of Max() values of a field in sql server

Assume that i have three field in my database like this :

ID    Title    MaxVisited

 1     hi          6
 2     bye         8
 3     How?        9
 4     News!       8
 5     Hey         3
 6     Thanks      9

now i want to select Title three of max value of MaxVisited.. the result which i want:

Thanks , How? , News!

Upvotes: 0

Views: 78

Answers (3)

Avt
Avt

Reputation: 17043

SELECT TOP 3 Title from [your_table] 
order by MaxVisited, ID desc

Upvotes: 0

dknaack
dknaack

Reputation: 60448

Just select the top 3 and order by MaxVisited and (if necessary) the Id column

SELECT TOP 3 Title from [TableName] 
order by MaxVisited, Id desc

Upvotes: 3

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Try this

SELECT TOP 3 Title 
From [TableName] 
order by MaxVisited,Title desc

Upvotes: 1

Related Questions