Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004
    Posts
    3

    Unanswered: Insert..Update...on duplicate error

    I am getting the error

    ERROR 1064: You have an error in your SQL syntax near 'ON DUPLICATE KEY UPDATE d_email='mynewemail@myemail.com' at line 1

    when I run the query

    insert into tablename (d_catid,d_focus,d_email) VALUES (2,1,'myname@myemail.com') ON DUPLICATE KEY UPDATE d_email='mynewemail@myemail.com'

    The table is described as

    mysql> desc tablename;
    +---------+--------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +---------+--------------+------+-----+---------+-------+
    | d_catid | int(11) | YES | | NULL | |
    | d_focus | int(11) | | PRI | 0 | |
    | d_email | varchar(200) | YES | | NULL | |
    +---------+--------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)

    Please help.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    are you by any chance on mysql 4.1?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2004
    Posts
    3
    No,

    MySQL 3.23.54

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, that's your problem, then, isn't it

    that only works in 4.1

    says so right in the docs
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jun 2004
    Posts
    3
    Is there an alternative in this version that i can use?

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yep

    do a SELECT to see if it's there

    if it is, do an UPDATE, if it isn't, do an INSERT
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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