
- 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
MySQL query error with a table named “order”?
The order is a reserved word. To still use a reserved word, you need to use backticks around the column name. Let us first create a table −
mysql> create table `order` -> ( -> StudentId int -> ); Query OK, 0 rows affected (1.78 sec)
Insert some records in the table using insert command −
mysql> insert into `order` values(101); Query OK, 1 row affected (0.26 sec) mysql> insert into `order` values(210); Query OK, 1 row affected (0.18 sec) mysql> insert into `order` values(190); Query OK, 1 row affected (0.28 sec) mysql> insert into `order` values(180); Query OK, 1 row affected (0.46 sec) mysql> insert into `order` values(205); Query OK, 1 row affected (0.28 sec)
Display all records from the table using select statement −
mysql> select *from `order`;
This will produce the following output −
+-----------+ | StudentId | +-----------+ | 101 | | 210 | | 190 | | 180 | | 205 | +-----------+ 5 rows in set (0.00 sec)
Here is the query to use ‘order’ as table name using backticks −
mysql> select *from `order` order by StudentId desc limit 1;
This will produce the following output −
+-----------+ | StudentId | +-----------+ | 210 | +-----------+ 1 row in set (0.03 sec)
- Related Articles
- What is the MySQL syntax error in this query – Creating a table with reserved keyword?
- Selecting a value in custom order from another column in a MySQL table with a single query
- MySQL query to calculate sum from 5 tables with a similar column named “UP”?
- MySQL syntax error (in SELECT query) while using ‘group’ as table name
- Resolve Syntax error near “ORDER BY order DESC” in MySQL?
- Fix Error in MySQL syntax while creating a table column with name “index”?
- MySQL Error ERROR 1099 (HY000): Table was locked with a READ lock and can't be updated
- MySQL query to order rows with value greater than zero?
- How to order and select query with conditions in MySQL?
- Order a MySQL table by two columns?
- Insert multiple values in a temporary table with a single MySQL query?
- Delete records from a MySQL table with IN() in a single query
- Maintaining order in MySQL “IN” query?
- Order MySQL query by multiple ids?
- How to ORDER BY FIELD with GROUP BY in a single MySQL query?

Advertisements