simple query ".id" question

Discussion in 'MySQL' started by FunkyFresh, Aug 13, 2010.

  1. #1
    What does the '.id' mean? doesnt that just mean get the id from WPSC_TABLE_PRODUCT_CATEGORIES table. is that '.id' necessary?

    if not so, then why does 'nice-name' not have WPSC_TABLE_PRODUCT_CATEGORIES before it?

    THanks

    $sql = 'SELECT ' . WPSC_TABLE_PRODUCT_CATEGORIES . '.id, ' . WPSC_TABLE_PRODUCT_CATEGORIES . '.name, `nice-name` FROM '. WPSC_TABLE_PRODUCT_CATEGORIES . ' ';
    Code (markup):

     
    FunkyFresh, Aug 13, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    The .id and the .name means that you are querying for the id and the name columns. The WPSC_TABLE_PRODUCT_CATEGORIES will end up being the actual table name.
     
    jestep, Aug 13, 2010 IP
  3. FunkyFresh

    FunkyFresh Peon

    Messages:
    499
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    whats happening to 'nice-name'? whats it doing there?
    thanks btw
     
    FunkyFresh, Aug 13, 2010 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    When it's in back ticks like that it will return the value nice name every time. Without seeing the app/usage itself I can't see why someone would add that in there. I can;t think of any reason not to handle this on the application level.

    Basically this this query it would return something like:
    1 cat_name nice name
    2 other_cat_name nice name
    3 yet_another_cat_name nice name
     
    jestep, Aug 13, 2010 IP