
- 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
Resolve Syntax error near “ORDER BY order DESC†in MySQL?
The word order is a reserved order in MySQL and you have used it in the query. To get rid of the syntax error, you need to use backticks(` `) around the order.
The correct syntax is as follows −
select *from yourTableName ORDER BY `order` DESC;
Let us first create a table −
mysql> create table DemoTable ( `order` int ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-------+ | order | +-------+ | 89 | | 67 | | 90 | | 56 | +-------+ 4 rows in set (0.00 sec)
Following is the query to remove syntax error near ORDER BY −
mysql> select *from DemoTable ORDER BY `order` DESC;
Output
+-------+ | order | +-------+ | 90 | | 89 | | 67 | | 56 | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- Order by desc except a single value in MySQL
- Implement MySQL ORDER BY without using ASC or DESC?
- Resolve MySQL ERROR 1064 (42000): You have an error in your syntax?
- How to resolve the MySQL error “You have an error in your SQL syntax; check the manual\nthat corresponds to your MySQL server version for the right syntax to use near?â€
- How to ORDER BY DESC and display the first 3 records in MySQL?
- Fix a row value and then ORDER BY DESC rest of the values in MySQL
- Fix MySQL Error #1064 - You have an error in your SQL syntax… near 'TYPE=MyISAM?
- Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query
- MySQL query error with a table named “order�
- Declare syntax error in MySQL Workbench?
- How to order DESC by a field, but list the NULL values first?
- Order By date ASC in MySQL?
- Order by selected record in MySQL?
- MySQL Order by with case?
- MySQL Order By specific strings?

Advertisements