开发者

How do i only pull the top "x" rows from a table?

开发者 https://www.devze.com 2023-03-26 07:54 出处:网络
I have this query $query_return = database::query(\"SELECT * FROM tw ORDER BY time DESC\"); that pulls all the rows, however I only want the开发者_如何转开发 top x=8 rows.

I have this query

$query_return = database::query("SELECT * FROM tw ORDER BY time DESC");

that pulls all the rows, however I only want the开发者_如何转开发 top x=8 rows.

How do I modify it?

Thanks!


Use LIMIT:

SELECT * FROM tw ORDER BY time DESC LIMIT 8


Add a limit clause:

$query_return = database::query("SELECT * FROM tw ORDER BY time DESC LIMIT 8");


If code is for MS-SQL use TOP e.g. SELECT TOP (8) * FROM ....

0

精彩评论

暂无评论...
验证码 换一张
取 消