
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Fix MySQL Database Error #1064?
- Fix ERROR 1064 (42000) while creating a database in MySQL?
- Fix Error with TYPE=HEAP for temporary tables in MySQL?
- Fix Drop table view #1051 unknown table error in MySQL
- Fix: ERROR 1396 (HY000): Operation CREATE USER failed in MySQL?
- Fix MySQL Error #1064 - You have an error in your SQL syntax… near 'TYPE=MyISAM?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- Why the #1054 - Unknown column error occurs in MySQL and how to fix it?
- Fix Connectivity error in Java MySQL connection for connector to be set to class path?
- Fix ERROR 1093 (HY000): You can't specify target table for update in FROM clause while deleting the lowest value from a MySQL column?
- MySQL syntax error (in SELECT query) while using ‘group’ as table name
- Fix for MySQL ERROR 1406: Data too long for column” but it shouldn't be?
- How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?
- How to fix problems related to the JavaScript Void 0 Error?
- Select distinct values from two columns in MySQL?

Advertisements