SQL SELECT 语句

SQL SELECT 语句 #

SELECT 语句用于从数据库中选取数据。

结果被存储在一个结果表中,称为结果集。

SQL SELECT 语法

SELECT column_name,column_name FROM table_name;

SELECT * FROM table_name;

SELECT Column 实例 #

下面的 SQL 语句从 “domains” 表中选取 “domainname” 和 “icp” 列:

实例

MariaDB [learnsql]> select domainname,icp from domains;
+------------------+-----------+
| domainname       | icp       |
+------------------+-----------+
| aisoc.cn         | west.cn   |
| ado.ink          | west.cn   |
| nrdoc.com        | west.cn   |
| getos.org        | namesilo  |
| litiaotiao.cn    | west.cn   |
| dotbbq.com       | wanwang   |
| lyq.wiki         | wanwang   |
| les.moe          | namesilo  |
| regex.in         | namesilo  |
| wmts.top         | west.cn   |
| sharpbang.cn     | west.cn   |
| blbl.dev         | namesilo  |
| raspi.in         | namesilo  |
| pornie.in        | namesilo  |
| aosp.me          | namesilo  |
| bailuyuan.org    | namesilo  |
| linuxuc.com      | wanwang   |
| ustv.xyz         | namesilo  |
| unixetc.com      | wanwang   |
| ciux.org         | namesilo  |
| avlist.top       | namesilo  |
| suopo.net        | google    |
| vbar.xyz         | west.cn   |
| ltecn.com        | namesilo  |
| pornie.top       | namesilo  |
| sjcs.top         | west.cn   |
| imagemagick.top  | west.cn   |
| oppa.top         | west.cn   |
| kodis.top        | west.cn   |
| vpshz.top        | west.cn   |
| smdm.top         | west.cn   |
| commandline.top  | west.cn   |
| wxtx.top         | west.cn   |
| kjzx.top         | west.cn   |
| aido.cc          | west.cn   |
| ustv.top         | west.cn   |
| colorhexcode.top | west.cn   |
| rgbs.top         | west.cn   |
| autohotkey.top   | west.cn   |
| opensuse.top     | west.cn   |
| qgis.top         | west.cn   |
| hugotheme.top    | west.cn   |
| zjq.xyz          | dnspod.cn |
| alair.cn         | dnspod.cn |
| ymqd.net         | dnspod.cn |
| nasplus.cn       | dnspod.cn |
| manjushri.cn     | dnspod.cn |
| pushto.cn        | dnspod.cn |
| gfwlist.cn       | dnspod.cn |
| byhzg.cn         | dnspod.cn |
| guwendaquan.cn   | west.cn   |
| mua.wiki         | gandi.net |
+------------------+-----------+
52 rows in set (0.001 sec)

SELECT * 实例 #

下面的 SQL 语句从 “domains” 表中选取所有列:

实例

MariaDB [learnsql]> select * from domains;
+----+-----------+------------------+------------+------------+
| ID | ICP       | DomainName       | RegDate    | EndDate    |
+----+-----------+------------------+------------+------------+
|  1 | west.cn   | aisoc.cn         | 2021/8/17  | 2022/8/17  |
|  2 | west.cn   | ado.ink          | 2020/8/22  | 2022/8/22  |
|  3 | west.cn   | nrdoc.com        | 2021/9/7   | 2022/9/7   |
|  4 | namesilo  | getos.org        | 2016/10/9  | 2022/10/9  |
|  5 | west.cn   | litiaotiao.cn    | 2021/10/9  | 2022/10/9  |
|  6 | wanwang   | dotbbq.com       | 2017/10/28 | 2022/10/28 |
|  7 | wanwang   | lyq.wiki         | 2018/12/27 | 2022/12/28 |
|  8 | namesilo  | les.moe          | 2015/12/31 | 2022/12/31 |
|  9 | namesilo  | regex.in         | 2020/1/3   | 2023/1/3   |
| 10 | west.cn   | wmts.top         | 2021/1/11  | 2023/1/11  |
| 11 | west.cn   | sharpbang.cn     | 2022/1/12  | 2023/1/12  |
| 12 | namesilo  | blbl.dev         | 2020/1/17  | 2023/1/17  |
| 13 | namesilo  | raspi.in         | 2014/2/27  | 2023/2/27  |
| 14 | namesilo  | pornie.in        | 2016/3/10  | 2023/3/10  |
| 15 | namesilo  | aosp.me          | 2016/3/17  | 2023/3/17  |
| 16 | namesilo  | bailuyuan.org    | 2017/3/23  | 2023/3/23  |
| 17 | wanwang   | linuxuc.com      | 2016/3/24  | 2023/3/24  |
| 18 | namesilo  | ustv.xyz         | 2018/3/24  | 2023/3/25  |
| 19 | wanwang   | unixetc.com      | 2017/3/30  | 2023/3/30  |
| 20 | namesilo  | ciux.org         | 2010/4/26  | 2023/4/26  |
| 21 | namesilo  | avlist.top       | 2021/6/5   | 2023/6/5   |
| 22 | google    | suopo.net        | 2020/6/17  | 2023/6/17  |
| 23 | west.cn   | vbar.xyz         | 2020/7/20  | 2023/7/20  |
| 24 | namesilo  | ltecn.com        | 2014/7/26  | 2025/7/26  |
| 25 | namesilo  | pornie.top       | 2016/3/10  | 2027/3/10  |
| 26 | west.cn   | sjcs.top         | 2017/9/5   | 2027/9/5   |
| 27 | west.cn   | imagemagick.top  | 2017/10/24 | 2027/10/24 |
| 28 | west.cn   | oppa.top         | 2015/12/29 | 2027/12/29 |
| 29 | west.cn   | kodis.top        | 2018/1/25  | 2028/1/25  |
| 30 | west.cn   | vpshz.top        | 2018/7/18  | 2028/7/18  |
| 31 | west.cn   | smdm.top         | 2018/9/10  | 2028/9/10  |
| 32 | west.cn   | commandline.top  | 2020/10/21 | 2029/10/21 |
| 33 | west.cn   | wxtx.top         | 2020/8/11  | 2030/8/11  |
| 34 | west.cn   | kjzx.top         | 2020/8/16  | 2030/8/16  |
| 35 | west.cn   | aido.cc          | 2020/9/22  | 2030/9/22  |
| 36 | west.cn   | ustv.top         | 2020/10/13 | 2030/10/13 |
| 37 | west.cn   | colorhexcode.top | 2021/1/27  | 2031/1/27  |
| 38 | west.cn   | rgbs.top         | 2021/2/25  | 2031/2/25  |
| 39 | west.cn   | autohotkey.top   | 2021/3/3   | 2031/3/3   |
| 40 | west.cn   | opensuse.top     | 2021/3/25  | 2031/3/25  |
| 41 | west.cn   | qgis.top         | 2021/8/23  | 2031/8/23  |
| 42 | west.cn   | hugotheme.top    | 2022/2/18  | 2032/2/18  |
| 43 | dnspod.cn | zjq.xyz          | 2021-08-06 | 2022-10-24 |
| 44 | dnspod.cn | alair.cn         | 2021-08-06 | 2022-12-10 |
| 45 | dnspod.cn | ymqd.net         | 2022-01-28 | 2023-03-03 |
| 46 | dnspod.cn | nasplus.cn       | 2022-01-28 | 2023-03-08 |
| 47 | dnspod.cn | manjushri.cn     | 2022-01-28 | 2023-03-11 |
| 48 | dnspod.cn | pushto.cn        | 2022-01-28 | 2023-03-12 |
| 49 | dnspod.cn | gfwlist.cn       | 2022-01-28 | 2023-03-23 |
| 50 | dnspod.cn | byhzg.cn         | 2022-01-28 | 2023-04-14 |
| 51 | west.cn   | guwendaquan.cn   | 2022/6/9   | 2023/6/9   |
| 52 | gandi.net | mua.wiki         | 2022/7/19  | 2023/7/19  |
+----+-----------+------------------+------------+------------+
52 rows in set (0.000 sec)