您需要明确给出名称,也可以删除AS命令。让我们首先创建一个表-mysql> create table DemoTable
(
Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name varchar(20)
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable(Name) values('John');
mysql> insert into DemoTable(Name) values('Larry');
mysql> insert into DemoTable(Name) values('Sam');
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+----+-------+
| Id | Name |
+----+-------+
| 1 | John |
| 2 | Larry |
| 3 | Sam |
+----+-------+
3 rows in set (0.00 sec)
情况1-使用AS命令查询MySQL别名。mysql> select Id,Name AS FirstName from DemoTable;
这将产生以下输出-+----+-----------+
| Id | FirstName |
+----+-----------+
| 1 | John |
| 2 | Larry |
| 3 | Sam |
+----+-----------+
3 rows in set (0.00 sec)
情况2:查询没有AS的MySQL别名-mysql> select Id,Name FirstName from DemoTable;
这将产生以下输出-+----+-----------+
| Id | FirstName |
+----+-----------+
| 1 | John |
| 2 | Larry |
| 3 | Sam |
+----+-----------+
3 rows in set (0.00 sec)