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

  • Home
  • SEARCH
  • 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 842745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:00:56+00:00 2026-05-15T06:00:56+00:00

I have a simple table made up of two columns: col_A and col_B .

  • 0

I have a simple table made up of two columns: col_A and col_B.

The primary key is defined over both.

I need to update some rows and assign to col_A values that may generate duplicates, for example:

UPDATE `table` SET `col_A` = 66 WHERE `col_A` = 70

This statement sometimes yields a duplicate key error.

I don’t want to simply ignore the error with UPDATE IGNORE, because then the rows that generate the error would remain unchanged. Instead, I want them to be deleted when they would conflict with another row after they have been updated

I’d like to write something like:

UPDATE `table` SET `col_A` = 66 WHERE `col_A` = 70 ON DUPLICATE KEY REPLACE

which unfortunately isn’t legal in SQL, so I need help finding another way around.
Also, I’m using PHP and could consider a hybrid solution (i.e. part query part php code), but keep in mind that I have to perform this updating operation many millions of times.

thanks for your attention,

Silvio

Reminder: UPDATE‘s syntax has problems with joins with the same table that is being updated

EDIT: sorry, the column name in the WHERE clause was wrong, now I fixed it

  • 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-15T06:00:57+00:00Added an answer on May 15, 2026 at 6:00 am

    Answer to revised question:

    DELETE FROM
        table_A
    USING
        table AS table_A
        JOIN table AS table_B ON
            table_A.col_B = table_B.col_B AND
            table_B.col_A = 70
    WHERE
        table_A.col_A = 66
    

    This gets rid of the rows that would cause problems. Then you issue your UPDATE query. Ideally you will do it all inside a transaction to avoid a situation where troublesome rows are re-inserted in between the two queries.

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

Sidebar

Related Questions

I have one table: drupal.comments , with amongst others, the columns: cid: primary key
I have simple table creating script in Postgres 9.1. I need it to create
I have a simple table view which is editable. All I need the user
I have a table that holds only two columns - a ListID and PersonID.
Hi, I have made this simple script but I need to have it check
How can I create a table of two columns, made by div's, where the
Simple question (I hope): I have a simple two column table, a measurement and
I have made a simple table form here in jsfiddle . I also put
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>

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.