MariaDB From子句

MariaDB FROM子句用於從表中獲取數據。它也被用來連接表,這將在後面章節中學習。

語法:

SELECT columns_names FROM table_name;

示例1:

假設要從"students"表中檢索所有學生信息。參考以下語句中,From語句的用法 -

SELECT * FROM students;

執行上面查詢語句,得到以下結果 -

MariaDB [testdb]> SELECT * FROM students;
+------------+--------------+-----------------+----------------+
| student_id | student_name | student_address | admission_date |
+------------+--------------+-----------------+----------------+
|          1 | Maxsu        | Haikou          | 2017-01-07     |
|          3 | JMaster      | Beijing         | 2016-05-07     |
|          4 | Mahesh       | Guangzhou       | 2016-06-07     |
|          5 | Kobe         | Shanghai        | 2016-02-07     |
|          6 | Blaba        | Shengzhen       | 2016-08-07     |
|          7 | Maxsu        | Sanya           | 2017-08-08     |
|          8 | Maxsu        | Haikou          | 2015-11-17     |
+------------+--------------+-----------------+----------------+
7 rows in set (0.00 sec)

示例2:

從students表中選擇一個特定的列。例如,要選擇student_idstudent_name列,如下查詢語句 -

SELECT student_id,student_name FROM students;

執行上面查詢語句,得到以下結果 -

MariaDB [testdb]> SELECT student_id,student_name FROM students;
+------------+--------------+
| student_id | student_name |
+------------+--------------+
|          1 | Maxsu        |
|          3 | JMaster      |
|          4 | Mahesh       |
|          5 | Kobe         |
|          6 | Blaba        |
|          7 | Maxsu        |
|          8 | Maxsu        |
+------------+--------------+
7 rows in set (0.00 sec)