1

Possible Duplicate:
How do I escape reserved words used as column names? MySQL/Create Table

This should be an easy one to answer, I hope. I have a series of column names in various tables named things like T(x,y,t), T(x,y,t-1), T(x+1,y,t), etc. I know that having parentheses in column names is frowned upon, but how do I reference a name like this (with the table name) in the SELECT clause?

For example, I've tried things like

SELECT A.JDAY, 'B.T(x,y,t)'
FROM A, B

and

SELECT A.JDAY, B.'T(x,y,t)'
FROM A, B

...but neither of those seem to be working.

Community
  • 1
  • 1
Amy
  • 183
  • 3
  • 16
  • 1
    The backtick is the default character for "quoted identifiers". With `SET sql_mode = 'ANSI_QUOTES'` (or any special combination mode that includes ANSI_QUOTES), you can also use the double quote character. Though we usually only enable that and actually use double quotes when we are working with scripts that already have the double quotes, and we want MySQL to accommodate. No, the backtick character doesn't have any other special use in MySQL, except to "quote" identifiers. – spencer7593 Jul 20 '12 at 21:43

1 Answers1

6

you could use back tick:

SELECT A.JDAY, B.`T(x,y,t)`
FROM A, B

Not tested, but it should do the trick.

Sebas
  • 21,192
  • 9
  • 55
  • 109
  • 1
    Please, use INNER JOIN or CROSS JOIN instead of comma to express table joins. – Sebas Jul 20 '12 at 21:25
  • Awesome, didn't think of that, thank you! Are there any other uses for the backtick? (I use joins typically, but I just made up a short blurb of code as an example here.) – Amy Jul 20 '12 at 21:31
  • Well, it seemed to work with my little test piece, but when I incorporate that into my larger query I'm getting an "Access violation" error. – Amy Jul 20 '12 at 21:43
  • Nevermind, restarted Navicat and it's working now! Thanks again! – Amy Jul 20 '12 at 21:51
  • no problem. For your question, it is also useful for table names. – Sebas Jul 20 '12 at 22:07