欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL单表查询

程序员文章站 2023-01-29 08:21:37
单表查询 1、查询所有: select * from 表名; 2、查询选中字段数据: select 字段名 from 表名; 3、查询指定条件下的数据: select 字段名 from 表名 where 条件(例id>3); 4、查询后为字段取别名 as: select 原名 as 更改名 from ......

单表查询

1、查询所有:

select * from 表名;

2、查询选中字段数据:

select 字段名 from 表名;

3、查询指定条件下的数据:

select 字段名 from 表名 where 条件(例id>3);

4、查询后为字段取别名 as:

select 原名 as 更改名 from 表名;

5、模糊查询 like:

select *from 表名 where 字段名 like 该字段里的其中一个字符(例‘小%’,则查询出该字段里所有以小字开头的数据,‘%百分号代表后面多个’,‘_下划线代表一个’)

6、排序 order by:

select * from 表名 order by 字段名;(默认升序:asc)

select * from 表名 order by 字段名 desc;(降序:desc)

7、限制显示数据的数量 limit :

select * from 表名 order by 字段名 limit 2;# 以字段名的升序取两条数据,2为限制两条数据

select * from 表名 order by 字段名 limit 2,2;