问题描述
如何从一个包含1000多个记录的表中仅获取10条记录.我有一个包含rowid,名称,成本的测试表.
How can I get only 10 records from a table where there are more than 1000 records. I have a test table with rowid, name, cost.
select name, cost from test;
在这里,我只想选择前10行,而不要选择rowid.
here I want to select only first 10 rows and dont want to select rowid.
推荐答案
要选择前十条记录,可以使用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
这篇关于如何从mysql中的表中选择N条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!