一、 数据查询语言(DQL)(重中之重)
完整语法格式:
select 表达式1|字段,....
[from 表名 where 条件]
[group by 列名]
[having 条件]
[order by 列名 [asc|desc]]
[limit 位置,数量]
<1> 普通查询
select 查询表达式; // 最简单的sql语句,是一个函数
select database();
select version();
select now();
<2> 条件查询
where 条件表达式, 支持运算符和函数
MySQL支持的运算符:
=、 !=、 >、 >=、
and、 or、 not
is null、 is not null
between...and... (区间查询,多少到多少之间)
in(set);
like 通配符和占位符: % _ (模糊查询)
%: 表示0个或者多个字符
_: 表示占位一个
-- 查询所有的老师信息
select * from teacher;
-- 查询id 大于2的老师信息
select * from teacher where id>2;
-- 查询姓名为空的老师信息 在数据库中null永远都不等于null,那么怎么去判断null值?通过 is null / is not null
-- select * from teacher where name=null; # 错误
s