1.檢索不同的行
查詢數(shù)據(jù),過濾指定列名重復(fù)的數(shù)據(jù),在列名前面添加 distinct 關(guān)鍵字
例:select distinct vend_id from products
2.限制結(jié)果
查詢數(shù)據(jù),指定查詢開始行和查詢數(shù)量,使用 limit 關(guān)鍵字
-例:select vend_id from products limit 5 //第五行開始
-例:select vend_id from products limit 5,4 //第五行開始,查詢4行
3.排序查詢
查詢數(shù)據(jù),指定列名進(jìn)行排序,使用 order by 關(guān)鍵字
-例:select * from products order by id //以id進(jìn)行排序
-例:select * from products order by id,price //在id排序后的基礎(chǔ)上以price排序
*可使用 desc 設(shè)置降序查詢,asc 設(shè)置升序查詢[默認(rèn)排序方式
4.WHERE檢索

where子操作符
-例:select * from products where id <> 1
-例:select * from products where id between 5 and 10
-例:select * from products where price is null //查詢無值數(shù)據(jù)
5.WHERE其他子句
AND操作符、OR操作符、IN操作符、NOT操作符
-例:select * from products where id in(5,6) //檢索id等于5、id等于6的數(shù)據(jù)
-例:select * from products where id not in(5,6) //取反
6.LIKE操作符
百分號(hào)(%)通配符,'jet%'是以jet開頭的數(shù)據(jù)、下劃線通配符,'_ ton anvil'同理,單字符檢索
-例:select * from products where id like 'jet%'
-例:select * from products where id like '_ ton anvil' //.5 ton anvil不符合要求
7.正則表達(dá)式
使用 regexp 關(guān)鍵字,按照要求進(jìn)行查詢數(shù)據(jù),與like不同,只要文本中包含查找的數(shù)據(jù)就匹配。
-例:select * from products where id regexp '.00' //.表示匹配任意一個(gè)字符
-例:select * from products where id regexp '100|200' // |表示or
-例:select * from products where id regexp '[123] TON' // [123]等同于 ‘1|2|3’,[^123]代表除這些字符意外的
-例:select * from products where id regexp '[0-9] TON' // [0-9]等同于[0123456789],也可以寫字母[a-z]
-例:select * from products where id regexp '[0-9] TON' // [0-9]等同于[0123456789],也可以寫字母[a-z]

匹配特殊字符
-例:select * from products where id regexp '\\.' // \\表示查詢特殊字符,\\.查詢.。
-例:select * from products where id regexp '\\\' // \\\查詢\。

匹配字符類

匹配元字符
-例:select * from products where id regexp '\\([0-9] sticks?\\)' //查詢小括號(hào),0-9的數(shù)字,可有可無的s,如stick或sticks
-例:select * from products where id regexp '[[:digit:]]{4}' //查詢4位數(shù)字

定位元字符
-例:select * from products where id regexp '^[0-9\\.]' //匹配開始第一位為數(shù)字或.。
8.拼接字段
將兩個(gè)字段的信息合并為一個(gè)字段顯示,使用 Concat() 關(guān)鍵字
例:select Concat(vend_id,'(', vend_name,')') from products //輸出 1(汪強(qiáng))
9.字段別名(導(dǎo)出列)
使查詢的字段名顯示為指定的名稱,使用 as 關(guān)鍵字
例:select Concat(vend_id,'(', vend_name,')') as vend_title from products //字段名為 vend_title