
- 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
How to select a column name with spaces in MySQL?
To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `). Back tick is displayed in the keyboard below the tilde operator ( ~).
Firstly, create a table −
mysql> CREATE table SpaceColumn -> ( -> `Student Name` varchar(100) -> ); Query OK, 0 rows affected (0.48 sec)
Inserting records
mysql> INSERT into SpaceColumn values('John'); Query OK, 1 row affected (0.18 sec) mysql> INSERT into SpaceColumn values('Bob'); Query OK, 1 row affected (0.17 sec)
The syntax to get column name with space is as follows −
SELECT `column_name` from yourTableName;
Now I will apply the above syntax to get the result for my column. The query is as follows −
mysql> SELECT `Student Name` from SpaceColumn;
The following is the output −
+--------------+ | Student Name | +--------------+ | John | | Bob | +--------------+ 2 rows in set (0.00 sec)
- Related Articles
- Select the table name as a column in a UNION select query with MySQL?
- How to select data from a table where the table name has blank spaces in MYSQL?
- How to strip all spaces from a column in MySQL?
- Set Blank spaces in column names with MySQL?
- MySQL query to select everything to left of last space in a column with name records
- How to select a column of a matrix by column name in R?
- How to find tables with a specific column name in MySQL?
- How to SELECT * and rename a column in MySQL?
- MySQL SELECT to sum a column value with previous value
- Add a character in the end to column values with MySQL SELECT?
- How to get Column name on ResultSet in Java with MySQL?
- Lower case column names with MySQL SELECT?
- How to select the maximum value of a column in MySQL?
- How to select ID column as null in MySQL?
- Select minimum row value from a column with corresponding duplicate column values in MySQL

Advertisements