单表查询与多表查询
一、单表查询 1.完整的语法(语法级别的关键字的排列顺序) select distinct 字段1,字段2,字段3...from 库名.表名 where 过滤条件1 group by 分组依据 having 过滤条件2 order by 排序的字段 limit 限制显示的条数 ; 2.关键字执行的优先顺序 from > where > group by > having > select > distinct > order by > limit 2.1 找到表 2.2 从表中初步过滤出一条条数据 2.3 将对过滤出来的数据进行分组 2.4 将对过滤出来的数据进行二次过滤 2.5 执行select 2.6 将二次过滤的结果去重 2.7 将去重的结果进行排序 2.8 限制显示的条数 3.简单查询 语法中必须有的关键字:select (字段名1,字段名2) from 表名 1 create table employee( 2 id int not null unique auto_increment, 3 name varchar(20) not null, 4 sex enum('male','female') not null default 'male'