7

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?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
user718359
  • 505
  • 3
  • 13
  • 24

1 Answers1

22

Use backticks.

SELECT * FROM `Area One`
Intrepidd
  • 19,772
  • 6
  • 55
  • 63
  • 1
    Correct. Although this is definitely a very poor practice (I don't even let me developers use mixed-case -- perhaps I'm too stringent). – John Green May 19 '11 at 08:00
  • Mmm.. Does not work.. But maybe because of my setup.. This is the situation.. I have a db table.. users.. I have another table codes.. I have columns in the codes db, such as Zone, Area One, Area Two, Area Three etc.. On the page before I have the area (Area One, Area Two, Area Three etc) go into session.. session_area.. I also put Zone into session as session zone.. Different userid's are in the db.. So basically it is Zone, Area One, Area Two, Area Three 0001, userid_23, userid_78, userid_99 – user718359 May 19 '11 at 08:08
  • Now I get that to work out the user id I need and then get the relevent records from the user db.. – user718359 May 19 '11 at 08:08
  • "SELECT * FROM users WHERE userid = (select ".$_SESSION[`session_area`]." from zones WHERE zones='".$_SESSION['session_zones']."' limit 1)" – user718359 May 19 '11 at 08:12
  • Now this all works fine if Session called Area_One but not Area One? – user718359 May 19 '11 at 08:13