当前位置: 首页 > 教程 > MariaDB >

MariaDB From子句

精华
小牛编辑
122浏览
2023-03-14

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)