Mike Irish
Mike Irish

Reputation: 960

sql select top 10 values from database

I have a table called articles, each article has a rating value. I want to select * from the ten articles with the highest rating.

something along these lines

    $query = "SELECT TOP 10 rating FROM articles ORDER BY rating DESC";

I am confused about the TOP 10 part, I would usualy have SELECT * FROM

Upvotes: 4

Views: 8140

Answers (2)

Mayank Sahu
Mayank Sahu

Reputation: 1

you can do so by folloing SQL Query

 SELECT * FROM article ORDER BY rating DECS LIMIT 10;

Upvotes: -1

Andrew Rayner
Andrew Rayner

Reputation: 1064

Use LIMIT to do this

    $query = "SELECT * FROM articles ORDER BY rating DESC LIMIT 10";

Documentation here

Upvotes: 9

Related Questions