Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    13

    Unanswered: delete / select by primary key

    i have a table 'news' and i am trying to delete a row from it using something like this :

    delete from news where index="12"

    when i run that it gives me a syntax error at the index= section.

    if i do select * from news where index="12" it does the exact same error.

    my table looks like this :

    +--------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +--------+--------------+------+-----+---------+----------------+
    | index | int(11) | | PRI | NULL | auto_increment |
    | author | varchar(50) | YES | | NULL | |
    | title | varchar(100) | YES | | NULL | |
    | data | text | YES | | NULL | |
    | date | date | YES | | NULL | |
    +--------+--------------+------+-----+---------+----------------+

    and if i select * from news, the row with index 12 is:

    | 12 | test | testing | testing | 2005-01-03 |


    any ideas? i can select/delete based on other values just not index. is it maybe the fact that i named it index?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    it's a numeric column, right?

    try the query without the quotes around the 12

    yes, index is a reserved word, so try it with backticks around the name

    ... where `index` = 12
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2003
    Posts
    13
    yeah i tried it with/without quotes with no luck, but putting the `'s around it worked. thanks

Posting Permissions

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