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}' |