Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql select top 10 values from database

Tags:

sql

php

mysql

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

like image 889
Michael Grinnell Avatar asked Oct 15 '25 19:10

Michael Grinnell


1 Answers

Use LIMIT to do this

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

Documentation here

like image 154
Andrew Rayner Avatar answered Oct 18 '25 07:10

Andrew Rayner