數(shù)據(jù)庫(kù)的操作總結(jié)就是:增刪改查(CURD),今天記錄一下基礎(chǔ)的檢索查詢工作。
檢索MySQL1.查詢表中所有的記錄
mysql> select * from apps; +----+------------+-----------------------+---------+ | id | app_name | url | country | +----+------------+-----------------------+---------+ | 1 | QQ APP | http://im.qq.com | CN | | 2 | 微博 APP | http://weibo.com | CN | | 3 | 淘寶 APP | http://www.taobao.com | CN | +----+------------+-----------------------+---------+ 3 rows in set (0.00 sec)2. 查詢表中某列(單列)的記錄
mysql> select app_name from apps; +------------+ | app_name | +------------+ | QQ APP | | 微博 APP | | 淘寶 APP | +------------+ 3 rows in set (0.00 sec)3.檢索表中多列的記錄,列名之間用逗號(hào)分開(kāi)
mysql> select id, app_name from apps; +----+------------+ | id | app_name | +----+------------+ | 1 | QQ APP | | 2 | 微博 APP | | 3 | 淘寶 APP | +----+------------+ 3 rows in set (0.00 sec)4.檢索不重復(fù)的記錄,distinct關(guān)鍵字
mysql> select * from apps; +----+------------+-----------------------+---------+ | id | app_name | url | country | +----+------------+-----------------------+---------+ | 1 | QQ APP | http://im.qq.com | CN | | 2 | 微博 APP | http://weibo.com | CN | | 3 | 淘寶 APP | http://www.taobao.com | CN | | 4 | QQ APP | http://im.qq.com | CN | +----+------------+-----------------------+---------+ 4 rows in set (0.00 sec) 上面表中是所有的數(shù)據(jù),可以看到第1條和第4條數(shù)據(jù)是一樣的,如果想要檢索時(shí)不想出現(xiàn)重復(fù)的數(shù)據(jù),可以使用distinct關(guān)鍵字,并且需要放在所有列的前面 mysql> select distinct app_name from apps; +------------+ | app_name | +------------+ | QQ APP | | 微博 APP | | 淘寶 APP | +------------+ 3 rows in set (0.00 sec)5.限制檢索記錄的數(shù)量, limit關(guān)鍵字
mysql> select * from apps limit 2; +----+------------+------------------+---------+ | id | app_name | url | country | +----+------------+------------------+---------+ | 1 | QQ APP | http://im.qq.com | CN | | 2 | 微博 APP | http://weibo.com | CN | +----+------------+------------------+---------+ 2 rows in set (0.00 sec) limit后面可以跟兩個(gè)值, 第一個(gè)為起始位置, 第二個(gè)是要檢索的行數(shù) mysql> select * from apps limit 1, 2; +----+------------+-----------------------+---------+ | id | app_name | url | country | +----+------------+-----------------------+---------+ | 2 | 微博 APP | http://weibo.com | CN | | 3 | 淘寶 APP | http://www.taobao.com | CN | +----+------------+-----------------------+---------+ 2 rows in set (0.00 sec)5.limit關(guān)鍵字和offset配合使用
limit可以配合offset使用, 如limit 2 offset 1(從行1開(kāi)始后的2行,默認(rèn)行數(shù)的角標(biāo)為0) mysql> select * from apps limit 2 offset 1; +----+------------+-----------------------+---------+ | id | app_name | url | country | +----+------------+-----------------------+---------+ | 2 | 微博 APP | http://weibo.com | CN | | 3 | 淘寶 APP | http://www.taobao.com | CN | +----+------------+-----------------------+---------+ 2 rows in set (0.00 sec)
我的網(wǎng)站:https://wayne214.github.io
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/17882.html
摘要:通過(guò)這個(gè)函數(shù)可以很方便的在程序運(yùn)行期間執(zhí)行很多常見(jiàn)操作。此文可以轉(zhuǎn)載,但轉(zhuǎn)載前需要發(fā)郵件到進(jìn)行溝通,未溝通的均視作侵權(quán)。 index.php index.php 是整個(gè)框架的入口文件,也就是說(shuō)所有的請(qǐng)求都要從它這里開(kāi)始。因?yàn)?index.php 源碼非常簡(jiǎn)潔,那么我們直接放一張?jiān)创a截圖,按著截圖說(shuō)一下源碼。 showImg(https://segmentfault.com/img/re...
閱讀 1372·2021-09-02 10:19
閱讀 1111·2019-08-26 13:25
閱讀 2120·2019-08-26 11:37
閱讀 2427·2019-08-26 10:18
閱讀 2686·2019-08-23 16:43
閱讀 3033·2019-08-23 16:25
閱讀 788·2019-08-23 15:53
閱讀 3312·2019-08-23 15:11