
- 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
Why I am facing a problem using the field 'from' in SQL query?
You cannot use from as a column name directly because from is a reserved word in MySQL. To avoid this, you need to use backtick symbol. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, `from` varchar(100), Name varchar(10) ); Query OK, 0 rows affected (0.92 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(`from`,Name) values('US','John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(`from`,Name) values('UK','Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(`from`,Name) values('AUS','David'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+------+-------+ | Id | from | Name | +----+------+-------+ | 1 | US | John | | 2 | UK | Carol | | 3 | AUS | David | +----+------+-------+ 3 rows in set (0.00 sec)
Following is the query to use from reserved word as a column name −
mysql> select `from` from DemoTable;
This will produce the following output −
+------+ | from | +------+ | US | | UK | | AUS | +------+ 3 rows in set (0.00 sec)
- Related Articles
- I am facing problem in using include directive tag in jsp. Please share a working example.
- Remove 20% from stored price in MySQL field, using SQL query?
- Problem using the column name 'from' in a MySQL query?
- Facing Problem in retrieving HTML5 video duration
- I am having problem to understand the concept of positive and negative terminal
- Running a SQL query from specific month in SAP DB
- How can I write an SQL IN query with a Python tuple?
- Identify me, who am I- I am a planet and I look like Earth"."
- I am getting GUID Key columns truncated while using proxy ERP tables to query SAP tables
- \nLoad and unload a table in SAP HANA using SQL query
- Why am I not getting the desired results despite working very hard?
- Who I Am
- MySQL query to extract last word from a field?
- MySQL query to extract first word from a field?
- Despite being rich, why am I not able to get happiness?

Advertisements