SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a column called "desc"

    Hey -- I'm currently working my way through Mr. Yank's PHP/MySQL book and jumped in tonight.

    I was in the process of creating my very first table and kept running into an error message. I wanted to call one of the columns "desc" as in short for description but I kept getting a syntax error. So I played with it and thought, OK, I'll rename it "tell." Well, sure enough "tell" worked while "desc" produced syntax errors. How come?

    These were nothing but simple TEXT columns.

  2. #2
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you need a good MySQL tutorial. "DESC" is a reserved keyword in SQL. It is an abbreviation for DESCENDING, which is used in ORDER BY statements.

    MySQL Manual

    Enjoy!
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."


  3. #3
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DESC is a reserved word for descending when you are ordering your columns highest to lowest value hence the error.

    Dang, beat by seconds!

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need something like...

    SELECT * FROM blah WHERE `desc` = 'Hello'

  5. #5
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes bluesaga, you are right, you can use backquotes. Better practice though it to rename a column named with a reserved word. Sooner or later those backticks are going to be forgotten.


Bookmarks

Posting Permissions

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