当前位置:Gxlcms > 数据库问题 > MySQL 查询数据

MySQL 查询数据

时间:2021-07-01 10:21:17 帮助过:14人阅读

* from test; +----+--------+ | id | name | +----+--------+ | 1 | apple | | 2 | banana | | 3 | cherry | | 4 | apple | | 5 | banana | | 6 | cherry | +----+--------+
mysql> select * from test;                                # 查询所有数据
mysql> select id,name from test;                          # 只查询 id,name 两个字段的数据
mysql> select * from test where id=2;                     # 只查询 id 为 2 的数据
mysql> select * from test where id=1 and name=apple;    # 使用 and 查询
mysql> select * from test where id=1 or name=banana;    # 使用 or 查询
mysql> select * from test where id in (1,3);              # 使用 in 查询,表示只查询 id 为 13 的数据
mysql> select * from test where id between 1 and 4;       # 使用 between...and... 查询,表示只查询 id 在 1-4 之间的数据
mysql> select * from test where name like ‘app%‘; # 使用 like 查询,参考 http://www.cnblogs.com/pzk7788/p/6899748.html
mysql> select * from test order by id; # 对查询结果进行排序,参考:http://www.cnblogs.com/pzk7788/p/6911594.html
mysql
> select id,name from test limit 2; # 只查询前面两条数据

 

 

 

 

    

 

 

 

 

 

      

MySQL 查询数据

标签:表示   and   mys   order   between   rom   tar   mysq   sele   

人气教程排行