2007 Feb 8

Inserting duplicate indexed field in mysql

#1062 - Duplicate entry indexed_field' for key 2

Mysql will return a duplicate entry error when trying to insert a duplicate value in an indexed field in the database. We could modify our sql insert state to check for primary key duplicate or index field duplicate and automatically update the first field with the updated value like this.


INSERT INTO table1 (a,b,c)
SELECT a,b,c
FROM table2
WHERE a IS NOT NULL
ON DUPLICATE KEY
UPDATE table1.a = table2.a

0 TrackBacks

Listed below are links to blogs that reference this entry: Inserting duplicate indexed field in mysql.

TrackBack URL for this entry: http://www.tildemark.com/cgi-bin/mt4/mt-tb.cgi/56

Leave a comment

About this Entry

This page contains a single entry by tildemark published on February 8, 2007 10:51 AM.

SEO Challenge was the previous entry in this blog.

Enable curl with XAMPP on Windows XP is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recent Activity

Wednesday

  • tildemark tweeted, "@jjdoblados SmartBro wont work with linux because the installer is an exe file. plus SMARTBRO sucks my dialup connection is even faster."
  • tildemark tweeted, "i think i accidentally drank 2 dosage of my medication. now, im feeling dizzy. is there a way i cound unswallow it?"

Today

  • tildemark tweeted, "I'm feeling tired. i hope the clock will run a bit faster this time."
  • tildemark tweeted, "got sick for about 3 days. ended up finishing nwn2."

Thursday

  • tildemark tweeted, "im planning to move again, but i dont know where."

Sunday

  • tildemark tweeted, "I drank 3 sachets of instant coffee, ang now i cant sleep even if my eyes are sleepy? I can hear voices.wtf"

Friday

  • tildemark tweeted, "im so sleepy. Zzzzzzzz"

Sunday

  • tildemark tweeted, "some of my scipts are not working with godaddy. but works fine on the others. not mention their poorly coded admin page"

Thursday

  • tildemark tweeted, "so many pending tasks i need to finish. need more coffee !!!"
  • tildemark tweeted, "@gmtristan i dont think that is true."