Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010

    Unanswered: Naming columns with numbers


    I am pretty new to MySQL and the only previous database use I have had is Access way back in school, so apologise if this is a seriously silly question.

    I have created a table named mq1. Within which I have created 11 fields/columns: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, & 10.

    How do I get all the information from column named '0'?

    I tried the standard querying from the tutorial books:
    SELECT 0 FROM mq1 (column 0 from mq1 actually contains one entry: "hello" but this query doesn't return "hello", it returns '0'.)

    If I rename column '0' to 'a' and try the query again:
    SELECT a FROM mq1 (it returns "hello", which is what i want if I name the column 0)

    Do I need to escape the 0 somehow as it is a number? Or is it just not possible to name columns by numbers?

    Any help would be very much appreciated here. Thanks,


  2. #2
    Join Date
    Jun 2007
    I'd just recreate your table with proper named fields that explain perfectly what data they hold. You can also rename fields using the alter table command.

  3. #3
    Join Date
    Dec 2007
    Richmond, VA
    Provided Answers: 5
    You should definitely follow Mike's advice about proper naming of objects/attributes. Though to answer your first question try:
    SELECT "0" ....

  4. #4
    Join Date
    Sep 2009
    San Sebastian, Spain
    Naming fields with proper names will make it easier for you to develop later on. However, that is not to say what you are looking for cannot be done. Try the following

    CREATE TABLE tablename
    (`0` VARCHAR(100), ....);

    It also means that when you are writing your SELECT statements that you will need to include the ` as follows:

    SELECT `0` FROM tablename;
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts