修复 MySQL 中“select ClientId,ClientName,ClientAge, from tablename”中的错误
错误发生的原因是,就在“from tablename”之前,列名末尾有一个逗号。以下是你可能遇到的错误 −
mysql> select ClientId,ClientName,ClientAge, from DemoTable1391; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from DemoTable1391' at line 1
如上所述,要消除错误,你需要删除表中的最后一个逗号。让我们首先创建一个 −
mysql> create table DemoTable1391 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int -> ); Query OK, 0 rows affected (0.50 sec)
使用 insert 在表中插入一些记录 −
mysql> insert into DemoTable1391(ClientName,ClientAge) values('Chris',21); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1391(ClientName,ClientAge) values('Bob',23); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1391(ClientName,ClientAge) values('David',24); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1391(ClientName,ClientAge) values('Mike',28); Query OK, 1 row affected (0.24 sec)
使用 select 从表中显示所有记录 −
mysql> select * from DemoTable1391;
这将产生以下输出 −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 21 | | 2 | Bob | 23 | | 3 | David | 24 | | 4 | Mike | 28 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
以下查询用于消除错误,即使用 SELECT 语句并提取记录的正确方法 −
mysql> select ClientId,ClientName,ClientAge from DemoTable1391;
这将产生以下输出 −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 21 | | 2 | Bob | 23 | | 3 | David | 24 | | 4 | Mike | 28 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
广告