Home > Database > Mysql Tutorial > MySQL查询前几行_MySQL

MySQL查询前几行_MySQL

WBOY
Release: 2016-06-01 13:43:28
Original
1492 people have browsed it

bitsCN.com

当数据表中数据量大,而只需要其中某些字段的值做为验证时不需要所有数据,只需要查几行就可以,此时用limit


如:

1.select * from tags limit 4;    就是取4行数据,看看id或者其他需要的字段的的值是什么。
查询结果为:id=102或者..........,在下面就用id = 102

2.explain select * from tags where id=102;   检查该表中id或者其他字段是否为索引很有效。

+----+-------------+----------+------+---------------+------+---------+------+---------+-------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref  | rows    | Extra |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------+
|  102 | SIMPLE      | tags      | ALL  | NULL          | NULL | NULL    | NULL | 6226057 |       |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------+

可以看出在这里没有用到id 索引【为id建的索引一般为PRIMARY】




作者 hllnihao bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template