select * from 表名;php
select 字段名 from 表名;java
select * from 表名 where 条件;正则表达式
select * from 表名 where 条件 [not] in(元素1,元素2);函数
select * from 表名 where 条件 [not] between 取值1 and 取值2;code
like属于经常使用的比较运算符,实现模糊查询。它有通配符"%"和"_"。
select * from 表名 where 条件 like "%取值%";
在工做中的咱们也经常使用 concat()函数来拼接字段和通配符
select * from 表名 where 条件 like concat('%',取值,'%');regexp
select * from 表名 where 条件 is [not] null;排序
select * from 表名 where 条件1 and 条件2;
这里的条件能够是上面的任何一种,至关于逻辑运算的&&字符串
select * from 表名 where 条件1 or 条件2;
至关于逻辑运算的||it
seelct distinct 字段名 from 表名;io
select * from 表名 order by 字段 [ASC|DESC];
select * from 表名 group by 字段;
能够多字段分组,可是会对后面的字段分组,再对前面的字段细微分组
子查询就是select查询的是另外一个查询的附属。
字段名 regexp '匹配方式'
模式字符 | 含义 | 应用举例 |
---|---|---|
^ | 匹配以特定字符或者字符串开头的记录 | 查询以java开头的记录 <br> select * from tb_book where books regexp '^java' |
$ | 匹配以特定字符或字符串结尾的记录 | 查询以模块结尾的记录select * from tb_book where books regexp '模块$' |
. | 匹配字符串的任意一个字符,包括回车和换行符 | 查询包含P字符的记录select * from tb_book where books regexp 'P.' |
[字符集合] | 匹配“字符集合”中的任意一个字符 | 查询包含PCA字符的记录select * from tb_book where books regexp '[PCA]' |
[^字符集合] | 匹配除“字符集合”之外的任意一个字符 | 查询包含c~z字母之外的记录select * from tb_book where books regexp '[^c-z]' |
s1竖线s2竖线s3 | 匹配S一、S二、S3中任意一个字符串 | 查询包含php、c、java中任意一个的记录select * from tb_book where books regexp 'php竖线c竖线java' |
* | 匹配多个该符号以前的字符,包括0和1个 | 查询A字符前出现过J的记录select * from tb_book where books regexp 'J*A' |
+ | 匹配多个该符号以前的字符,包括1个 | 查询在A字符前至少出现过一个J的记录select * from tb_book where books regexp 'J+A' |
字符串{N} | 匹配字符串出现屡次 | 查询a字符出项3次的记录select * from tb_book where books regexp 'a{3}' |
字符串{M,N} | 匹配字符串出现至少M次,最多N次 | 查询A字符出现2-4次的记录select * from books regexp 'a{2,4}' |