• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

How to SELECT from table with ampersand ('&') in column name?!

Hi, I have unfortunately inherited a table that has data in it and that has an ampersand in one of the column names.

A 'desc table' provides the following:

mysql> desc benefits;
+------------------+------------+------+-----+---------+----------------+
| Field            | Type       | Null | Key | Default | Extra          |
+------------------+------------+------+-----+---------+----------------+
| ID               | int(11)    |      | PRI | NULL    | auto_increment |
[...]
| JITJ&T           | int(11)    | YES  |     | NULL    |                |

How do I select from the 'JITJ&T' column?
0
dmwoodru
Asked:
dmwoodru
  • 2
1 Solution
 
UmeshMySQL Principle Technical Support EngineerCommented:
Hi,

if you are getting problem in select query, then you can just rename the column name..

ALTER TABLE benefits CHANGE `JITJ&T` `JITJT` INT(11) DEFAULT NULL;
0
 
UmeshMySQL Principle Technical Support EngineerCommented:
try this..

make sure JITJ&T is in between ` & not in '

SELECT `JITJ&T`  FROM benefits
0
 
dmwoodruAuthor Commented:
ushastry's answer was perfect! Thanks very much. All points assigned to ushastry.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now