If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Insert..Update...on duplicate error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-14-04, 03:14
Neha1213 Neha1213 is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
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.
Reply With Quote
  #2 (permalink)  
Old 06-14-04, 03:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
are you by any chance on mysql 4.1?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-14-04, 04:03
Neha1213 Neha1213 is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
No,

MySQL 3.23.54
Reply With Quote
  #4 (permalink)  
Old 06-14-04, 04:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
well, that's your problem, then, isn't it

that only works in 4.1

says so right in the docs
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-15-04, 00:41
Neha1213 Neha1213 is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Is there an alternative in this version that i can use?
Reply With Quote
  #6 (permalink)  
Old 06-15-04, 04:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yep

do a SELECT to see if it's there

if it is, do an UPDATE, if it isn't, do an INSERT
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On