exxcellent
exxcellent

Reputation: 659

How do I SELECT the 5 highest values in an integer column?

What is the correct SQL statement if i wish to select the biggest 5 integer rows in the column "id"?

Currently i have something which is only getting id that are less than 5:

SELECT * FROM table WHERE id < 5

Upvotes: 1

Views: 1941

Answers (4)

AJ17
AJ17

Reputation: 308

SELECT top 5 * FROM mytable ORDER BY id DESC

Upvotes: 0

gbn
gbn

Reputation: 432271

5 largest "id" values:

SELECT * FROM table ORDER BY id DESC LIMIT 5

Upvotes: 2

Ariful Islam
Ariful Islam

Reputation: 7675

SELECT * FROM mytable ORDER BY id DESC LIMIT 5 

Upvotes: 4

Vijay
Vijay

Reputation: 5433

If I understand you correctly , i think you need this,

SELECT * FROM table ORDER BY id DESC LIMIT 5

Upvotes: 1

Related Questions