我们如何从 MySQL 表中获取一列或多列作为输出?


SELECT 命令可用于从 MySQL 表中获取一列或多列作为输出。 

 以下是获取一列或多列的示例

mysql> Select * from Student;

+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 1    | Gaurav  | Delhi   | Computers |
| 2    | Aarav   | Mumbai  | History   |
| 15   | Harshit | Delhi   | Commerce  |
| 17   | Raman   | Shimla  | Computers |
+------+---------+---------+-----------+

4 rows in set (0.01 sec)

mysql> Select Name,Subject from Student;

+---------+-----------+
| Name    | Subject   |
+---------+-----------+
| Gaurav  | Computers |
| Aarav   | History   |
| Harshit | Commerce  |
| Raman   | Computers |
+---------+-----------+

4 rows in set (0.00 sec)

以上查询从“Student”表中获取两列“Name”和“subject”。

mysql> Select Address from Student;

+---------+
| Address |
+---------+
| Delhi   |
| Mumbai  |
| Delhi   |
| Shimla  |
+---------+

4 rows in set (0.00 sec)

以上查询只从“Student”表中获取一列“Address”。

更新日期:2020-01-29

226 浏览

开启您的 职业

通过完成课程获取认证

开始吧
广告