+-
Mysql常用指令

去重指令

作用:去除select 查询出来的结果中重复的数据,重复数据只展示一列.
关键字:DISTINCT
用法:select DISTINCT source from student_table
source:去重的字段条件
student_table: 表名

查询版本号

select version() --查询系统版本(函数)

用来计算(表达式)

select 100*33 as 计算结果 --用来计算(表达式)

查询自增长步长(变量)

select @@auto_increment_increment --查询自增的步长(变量)

模糊查询

select * from student_table where name like '%刘%' --表示名字中带有刘字的条件;
select * from student_table where name like '刘%' --表示名字以刘字开头的条件;
select * from student_table where name like '刘_' --表示以刘后面只有一个子的条件;
select * from student_table where name like '刘__' --表示以刘后面只有两个字的条件.

is not null 不为空 is null 为空

select * from student_table where birthdate is not null; 查询出生日期不为空的学生信息.
select * from student_table where birthdate is null; 查询出生日期为空的学生信息.

join 联表查询

图示:
image.png

结论:inner join 是两边条件都符合的才能执行,null的不算

  left  join   tableone left join tabletwo ,以左边边为准,左边的null能被输出;