1.查看表中所有信息
select * from 表名;
2.查看表中部分信息
select 字段1,字段2… from 表名;
3.使用 where 语句选择
select * from 表名 where 条件;
(1)比较运算符
等于: =
大于: >
大于等于: >=
小于: <
小于等于: <=
不等于: != 或 <>
(2)逻辑运算符
and
or
not
4.模糊查找
(1)like
%表示任性个任意字符
_ 下划线表示任意一个字符
select * from 表名 where 字段名 like 条件;
(2)rlike
select * from 表名 where 字段名 rlike 正则表达式;
5.范围查找
(1)in not in
in表示在一个非连续的范围内
select * from where 字段 in (value1, value2…);
not in 不在括号值内。
select * from where 字段 not in (value1, value2…);
(2)between … and …在一个连续的范围内
select * from where 字段 between value1 and value2;
查找在值1到值2的数据
not between … and …不在这个连续的范围内
select * from where 字段 not between value1 and value2;
查找不在值1到值2的数据
这里注意 not in 与 not between 是一个整体语句,而一个not表示对某个条件的否定。
例如;
select * from where 字段 not between value1 and value2;
相当于:
select * from where not 字段 between value1 and value2;
(3) is null 判断为null
is not null 判断不为null
select * from where 字段 is null;
查找字段为空的数据
mysql基本的查询语句总结
猜你喜欢
转载自blog.csdn.net/zhangbiaoxiaoming/article/details/84948477
今日推荐
周排行