troubleshooting Question

MySQL Replace Into Question

Avatar of Isaiah Melendez
Isaiah Melendez asked on
* syntaxMySQL ServerSQL
4 Comments1 Solution25 ViewsLast Modified:

Hello, Experts,

I am curious about the REPLACE INTO statement in MySQL. I am currently using it as follows and I want to make sure I am using it correctly.

I have a historical table with 3 million-plus records. Then I have a staging table that will pull data down from an API daily and then run a replace statement into the historical table from the new data that came in. The new data coming in will be as follows:

  • New data that does not exist in the historical table
  • data existing in the historical but fields that have been changed (i.e: first name, total sales amount, etc)

What I expect to happen:

  • new data that does not exist will be inserted into the historical table
  • data that exists it will compare the primary key and update the rows that are in the staging table to the data in the historical

Is my assumption correct that my update process is working as expected?

The only thing that made me question the process is I made a change on the API level to ingest data that I thought was coming through and exposing it but it wasn't. It now is. When I checked the staging and historical tables this morning I would have expected the data to be updated for the fields that were missing data and do not see it updated.

My primary key is called repair_order_id and the records I am pulling down are based on a date called updaed_date which will show the latest records that are new or updated.

Tomas Helgi Johannsson
Database Administrator / Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004