sql从数据库中选择前10个值

时间:2021-09-15 20:40:27

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

我对TOP 10部分感到困惑,我通常会选择SELECT * FROM

2 个解决方案

#1


3  

Use LIMIT to do this

使用LIMIT执行此操作

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

Documentation here

文档在这里

#2


0  

you can do so by folloing SQL Query

你可以通过下面的SQL Query来做到这一点

 SELECT * FROM article ORDER BY rating DECS LIMIT 10;

#1


3  

Use LIMIT to do this

使用LIMIT执行此操作

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

Documentation here

文档在这里

#2


0  

you can do so by folloing SQL Query

你可以通过下面的SQL Query来做到这一点

 SELECT * FROM article ORDER BY rating DECS LIMIT 10;