Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:20:52+00:00 2026-05-22T03:20:52+00:00

I have an insert query for MySQL that looks like this: INSERT INTO table

  • 0

I have an insert query for MySQL that looks like this:

INSERT INTO table (foo, bar, fooo, baar, etc) VALUES (?,?,?,?,?)

It is used in a script to migrate some columns and keeps encountering duplicate primary keys. (Old database was awful and poorly maintained).

Is there a way I can just tell it to replace the whole offending row with the current values tossing out the old stuff entirely? I know there is an ON DUPLICATE KEY UPDATE command, but I don’t know if it would help me as all I’ve seen it used for is incrementing.

ANSWER: INSERT INTO table (foo, bar, fooo, baar, etc) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE foo=?, bar=?, fooo=?, baar=?, etc=?

Keep in mind that you have to add the values in the referenced array again to account for the extra question marks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:20:52+00:00Added an answer on May 22, 2026 at 3:20 am

    From MySQL manual:

    If you specify ON DUPLICATE KEY
    UPDATE, and a row is inserted that
    would cause a duplicate value in a
    UNIQUE index or PRIMARY KEY, an UPDATE
    of the old row is performed.

    What you said:

    Is there a way I can just tell it to
    replace the whole offending row with
    the current values tossing out the old
    stuff entirely?

    Conclusion: why don’t you just try it? It seems it does exactly what you want.


    Edit: Since you haven’t provided any examples of what you were trying to do, I’ll use some from MySQL’s website.

    INSERT INTO table (a,b,c) VALUES (1,2,3)
      ON DUPLICATE KEY UPDATE c=c+1;
    

    Or if you want something that relates more to real world:

    INSERT INTO table(int_field, str_field, float_field) VALUES (15, ‘some string’, ‘1.22’)
    ON DUPLICATE KEY UPDATE int_field = 15, str_field = ‘some_string’, float_field = ‘1.22’;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I have a query to insert a row into a table, which has a
I have a SQL Insert query inside a stored proc, for inserting rows into
Trying to do an insert, I have: jdbcTemplate.update(insert into...., new Object[]{foo.getId(), foo.getName()}) foo.getId() returns
I have a long running insert transaction that inserts data into several related tables.
I have a table that has an insert trigger on it. If I insert
I have used automation to insert values into a cell, however I have never
i have a proble, when insert something in foreign language into database. i have
I am a bit lost, this looks like some silly mistake - but I
Here's the thing, I don't have access to code that inserts data into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.