且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从mysql中的表中选择N条记录

更新时间:2023-01-28 19:48:37

要选择前十条记录,可以使用LIMIT,然后使用所需的记录数:

To select the first ten records you can use LIMIT followed by the number of records you need:

SELECT name, cost FROM test LIMIT 10

要从特定位置选择十条记录,可以使用LIMIT 10,100

To select ten records from a specific location, you can use LIMIT 10, 100

SELECT name, cost FROM test LIMIT 100, 10

这将显示记录101-110

This will display records 101-110

SELECT name, cost FROM test LIMIT 10, 100

这将显示记录11-111

This will display records 11-111

要确保您检索到正确的结果,请确保也对结果进行ORDER BY,否则返回的行可能是随机的

To make sure you retrieve the correct results, make sure you ORDER BY the results too, otherwise the returned rows may be random-ish

您可以阅读更多@ @ http://php.about.com/od /mysqlcommands/g/Limit_sql.htm

You can read more @ http://php.about.com/od/mysqlcommands/g/Limit_sql.htm