Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank spaces in column names with MySQL

Tags:

php

mysql

One of the column names in my database is two words long, including a blank space, i.e.: Area One. I am using SELECT and referring to the column names to pull the data I want. Now if I name the column _Area_One_, my SELECT works, but if I use _Area One_, it does not. It says Unknown column 'Area' in 'field list'

Ideas?

like image 803
user718359 Avatar asked May 19 '11 07:05

user718359


People also ask

Can you have spaces in MySQL column names?

Column names can contain any valid characters (for example, spaces). If column names contain any characters except letters, numbers, and underscores, the name must be delimited by enclosing it in back quotes (`).

How do I remove blank spaces in SQL column?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string. Note: Also look at the LTRIM() and RTRIM() functions.

How do I keep a column blank in MySQL?

You use NULL : insert into table tablename values (12, 13, 19, NULL, NULL, NULL, NULL, 1, NULL, 2, NULL, 5); You can also use '' if the column is a string and by "blank" you mean "empty string".

Can SQL database names have spaces?

Rule 2g (Special Characters) – Field names should contain only letters and numbers. No special characters, underscores or spaces should be used. Indexes will remain named as the SQL Server default, unless the index created is for a special purpose.


1 Answers

Use backticks.

SELECT * FROM `Area One`
like image 72
Intrepidd Avatar answered Sep 20 '22 15:09

Intrepidd