W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
SQL SELECT 語句用于從數(shù)據(jù)庫的表中取回所需的數(shù)據(jù),并以表的形式返回。返回的表被稱作結(jié)果集。
SELECT 語句的基本語法如下:
SELECT column1, column2, columnN FROM table_name;
這里,column1, column2...是你想要從表中取回的字段。如果要取回表中所有字段的話,可以使用下面的語法:
SELECT * FROM table_name;
考慮 CUSTOMERS 表,該表包含的記錄如下所示:
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
下面的例子將從 CUSTOMERS 表中獲取客戶的 ID、Name 和 Salary 字段:
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS;
運行結(jié)果如下所示:
+----+----------+----------+
| ID | NAME | SALARY |
+----+----------+----------+
| 1 | Ramesh | 2000.00 |
| 2 | Khilan | 1500.00 |
| 3 | kaushik | 2000.00 |
| 4 | Chaitali | 6500.00 |
| 5 | Hardik | 8500.00 |
| 6 | Komal | 4500.00 |
| 7 | Muffy | 10000.00 |
+----+----------+----------+
如果想要取回 CUSTOMERS 表中所有的字段的話,SQL 查詢應(yīng)該這么寫:
SQL> SELECT * FROM CUSTOMERS;
運行結(jié)果如下所示:
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: