

- 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
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 Questions & Answers
- 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?
- Facing Problem in retrieving HTML5 video duration
- Problem using the column name 'from' in a MySQL query?
- Why am I not getting the desired results despite working very hard?
- Despite being rich, why am I not able to get happiness?
- Running a SQL query from specific month in SAP DB
- An Anagram I Am in Python
- How can I write an SQL IN query with a Python tuple?
- I am getting GUID Key columns truncated while using proxy ERP tables to query SAP tables
- How can I see the constraints which are applied to a table stored in the database I am currently using?
- Why is bullying a major teenage problem?
- MySQL query to extract last word from a field?
- MySQL query to extract first word from a field?
- Load and unload a table in SAP HANA using SQL query
Advertisements