

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fix error in MySQL “select ClientId,ClientName,ClientAge, from tablename”
The error occurs because we have a comma at the end of the column names, just before “from tablename’. Here is the error you may have got −
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
To remove the error, as discussed above, you need to remove the last comma from the table. Let us first create a −
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 some records in the table using 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)
Display all records from the table using select −
mysql> select * from DemoTable1391;
This will produce the following output −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 21 | | 2 | Bob | 23 | | 3 | David | 24 | | 4 | Mike | 28 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
Following is the query to remove error i.e. this is the correct way of using SELECT statement and fetch records −
mysql> select ClientId,ClientName,ClientAge from DemoTable1391;
This will produce the following output −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 21 | | 2 | Bob | 23 | | 3 | David | 24 | | 4 | Mike | 28 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Fix Error in MySQL syntax while creating a table column with name “index”?
- What is “SELECT TRUE” in MySQL?
- Check if table exist without using “select from” in MySQL?
- Fix MySQL Database Error #1064?
- MySQL query error with a table named “order”?
- MySQL procedure to display a “select” statement twice
- Resolve Syntax error near “ORDER BY order DESC” in MySQL?
- Using combination of “AND” and “OR” in SELECT in ABAP
- MongoDB – Fix “Failed to convert from type String to type Date”?
- What is the MySQL error: “Data too long for column”?
- Why is “LIMIT 0” even allowed in MySQL SELECT statements?
- Deletions of “01” or “10” in binary string to make it free from “01” or “10” in C++ Program
- MongoDB equivalent of `select distinct(name) from collectionName where age = “25”`?
- How to work with “!=” or “not equals” in MySQL WHERE?
- Using “not equal” in MySQL?
Advertisements