简体   繁体   English

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

[英]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 我对TOP 10部分感到困惑,我通常会选择SELECT * FROM

Use LIMIT to do this 使用LIMIT执行此操作

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

Documentation here 文档在这里

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

 SELECT * FROM article ORDER BY rating DECS LIMIT 10;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM