12-基础SQL-DQL(数据查询语言)-分页查询(LIMIT)
DQL-介绍(常用)
DQL英文全称是Data Query Language(数据查询语言),数据查询语言用来查询数据库中表的记录
查询关键字:SELECT
DQL-语法
DQL-分页查询
语法:
SELECT 字段列表 FROM 表名 LIMIT 起始索引, 查询记录数;
案例:创建一个 emp 员工表,添加一些员工数据
CREATE TABLE emp( id int comment "编号", workno varchar(10) comment "工号", name varchar(10) comment "姓名", gender char(1) comment "性别", age tinyint unsigned comment "年龄", idcard char(18) comment "身份证号", workaddress varchar(50) comment "工作地址", entrydate date comment "入职时间" ) comment "员工表";
INSERT INTO emp (id,workno,name,gender,age,idcard,workaddress,entrydate) VALUES (1,"1","员工1","男","23","123456789000000000","江西","2023-8-31"), (2,"2","员工2","男","26","123456789000000001","河北","2023-12-31"), (3,"3","员工3","女","23","123456789000000002","河北","2023-5-31"), (4,"4","员工4","女","24","123456789000000003","山西","2023-3-31"), (5,"5","员工5","男","23","123456789000000000","江西","2023-8-31"), (6,"6","员工6","男","26","123456789000000001","河北","2023-12-31"), (7,"7","员工7","女","23","123456789000000002","河北","2023-5-31"), (8,"8","员工8","女","24","123456789000000003","山西","2023-3-31"), (9,"9","员工9","男","23","123456789000000000","江西","2023-8-31"), (10,"10","员工10","男","26","123456789000000001","河北","2023-12-31"), (11,"11","员工11","女","23","123456789000000002","河北","2023-5-31"), (12,"12","员工12","女","24","123456789000000003","山西","2023-3-31")
1)查询第一页的员工数据,每页展示10条记录
SELECT * FROM emp LIMIT 10;
# 或
SELECT * FROM emp LIMIT 0,10;
2)查询第二页的员工数据,每页展示10条记录(第二页只有两条数据)
SELECT * FROM emp LIMIT 10,10;