SQL, delimiters for field names which have spaces

access4.gif

How do you do SELECT <fieldname> FROM my_table if the field name has a space?

I had a table with a field name of "local authority" (no quotes) and wanted to do a SELECT. The space in teh middle caused a moment of delay and head-scratching.

You can't duck the issue because

SELECT local authority FROM tbl_nz_schools;

will cause a syntax error.

A rummage on Google got the answer from a MySql forum which seems worth repeating here: use the backwards quote as a delimiter. This is the obscure key which is typically to the left of the digit 1 on the keyboard.

SELECT `local authority` FROM tbl_nz_schools;

Top of page