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 7668975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:29:31+00:00 2026-05-31T15:29:31+00:00

First time I am trying duplicate key to have insert and update in one

  • 0

First time I am trying duplicate key to have insert and update in one query. What’s wrong with my query?

INSERT INTO tabletest(batchID, purchaseID) 
VALUES (553155, 892) ON DUPLICATE KEY 
UPDATE purchaseID = VALUES(purchaseID)

I’d like to insert or update if a batchID for a unique purchaseID exists. In the table purchaseID is UNIQUE.

  • 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-31T15:29:32+00:00Added an answer on May 31, 2026 at 3:29 pm

    If purchaseID is the column with the UNIQUE constraint, then you should update only batchID:

    INSERT INTO tabletest (batchID, purchaseID) 
      VALUES (553155, 892) 
    ON DUPLICATE KEY UPDATE 
      batchID = VALUES(batchID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time trying Pandas. I think I have a reasonable use
My first time trying out openGL on iOS. I have compiled the source and
First time trying to deal with users logging in with ASP.net and haven't had
this is my first time trying to use document classes in AS3 and im
It's my first time trying to make anything really interesting in C# and I
Hey everyone, my first time trying to draw a multi-color gradient in actionscript 3.
I'm exploring Rails for the first time and trying to add some fairly straightforward
This is the first time I'm trying random numbers with C (I miss C#).
I came across Side-by-side Assemblies for the first time today while trying to install
I'm trying wxpython for the first time. I've wrote a GUI for a python

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.