
- 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
Problem using the column name 'from' in a MySQL query?
You cannot use ‘from’ as column name directly because ‘from’ is a reserved word in MySQL.
If you want to still use it, then you need to use the 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 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 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
- Select the table name as a column in a UNION select query with MySQL?
- MySQL query to display columns name first name, last name as full name in a single column?
- Add a column count in a MySQL query on the basis of last name records?
- Why I am facing a problem using the field 'from' in SQL query?
- Can I get Age using BirthDate column in a MySQL query?
- MySQL query to display the first alphabet from strings in a separate column
- MySQL query to conduct a basic search for a specific last name in a column
- Change the column name from StudentName to FirstName in MySQL?
- How to get a specific column record from SELECT query in MySQL?
- Get database name from a query implemented in a MySQL Stored Procedure?
- How to add a column from a select query but the value from the new column will be the row count of the MySQL select query?
- Change the column name from a MySQL table with Student record?
- MySQL query to remove special characters from column values?
- MySQL query to replace special characters from column value
- MySQL query to fecth the domain name from email-id?

Advertisements