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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:41:57+00:00 2026-06-04T09:41:57+00:00

First, I’ll explain what I need to do, then how I think I can

  • 0

First, I’ll explain what I need to do, then how I think I can achieve it. My current plan seems very inefficient in theory, so my question is whether there is a better way of accomplishing it.

I have 2 Tables – lets call them ‘Products’ and ‘Products_Temp’, both are identical. I need to download a large number of files (XML or XLS) which contain product details (stock, pricing etc) from suppliers. These are then parsed into the Products_Temp table. Right now, I plan to use CF Scheduled Tasks to handle the downloading, and Navicat to do the actual parsing – I’m happy enough this is adequate and efficient enough.

The next step is where I’m struggling – once the file has been downloaded and parsed, I need to look for any changes in the data. This will be compared against the Products table. If a change is found, then that row should be added or updated (if it should be removed, then I’ll need to flag it rather than just delete it). Once all the data has been compared, the products_temp table should be emptied.

I’m aware of methods to compare tables and sync them accordingly, however the issue I have is the fact I’ll be handling multiple files from different sources. I had considered using only the products table and append/update, but I’m unsure how I could manage the ‘flag deleted’ requirement.

Right now, the only way I know I can make it work is to loop through the products_temp table, do various cfquerys and delete the row once complete. However, that seems incredibly inefficient, and given the fact we’re likely to be dealing with hundreds of thousands of rows, unlikely to be effective if we update everything daily.

Any pointers or advice on a better route would be appreciated!

  • 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-06-04T09:41:58+00:00Added an answer on June 4, 2026 at 9:41 am

    Both responses have possibilities. Just to expand on your options a little ..

    Option #1

    IF mySQL supports some sort of hashing, on a per row basis, you could use a variation of comodoro’s suggestion to avoid hard deletes.

    Identify Changed

    To identify changes, do an inner join on the primary key and check the hash values. If they are different, the product was changed and should be updated:

        UPDATE Products p INNER JOIN Products_Temp tmp ON tmp.ProductID = p.ProductID
        SET    p.ProductName = tmp.ProductName
               , p.Stock = tmp.Stock
               , ...
               , p.DateLastChanged = now()
               , p.IsDiscontinued  = 0
        WHERE  tmp.TheRowHash <> p.TheRowHash
    

    Identify Deleted

    Use a simple outer join to identify records that do not exist in the temp table, and flag them as “deleted”

        UPDATE Products p LEFT JOIN Products_Temp tmp ON tmp.ProductID = p.ProductID
        SET    p.DateLastChanged = now()
               , p.IsDiscontinued = 1
        WHERE  tmp.ProductID IS NULL
    

    Identify New

    Finally, use a similar outer join to insert any “new” products.

        INSERT INTO Products ( ProductName, Stock, DateLastChanged, IsDiscontinued, .. )
        SELECT tmp.ProductName, tmp.Stock, now() AS DateLastChanged, 0 AS IsDiscontinued, ...
        FROM   Products_Temp tmp LEFT JOIN Products p ON tmp.ProductID = p.ProductID
        WHERE  p.ProductID IS NULL
    

    Option #2

    If per row hashing is not feasible, an alternate approach is a variation of Sharondio’s suggestion.

    Add a “status” column to the temp table and flag all imported records as “new”, “changed” or “unchanged” through a series of joins. (The default should be “changed”).

    Identify UN-Changed

    First use an inner join, on all fields, to identify products that have NOT changed. (Note, if your table contains any nullable fields, remember to use something like coalesce Otherwise, the results may be skewed because null values are not equal to anything.

        UPDATE  Products_Temp tmp INNER JOIN Products p ON tmp.ProductID = p.ProductID
        SET     tmp.Status = 'Unchanged'
        WHERE   p.ProductName = tmp.ProductName
        AND     p.Stock = tmp.Stock
        ... 
    

    Identify New

    Like before, use an outer join to identify “new” records.

        UPDATE  Products_Temp tmp LEFT JOIN Products p ON tmp.ProductID = p.ProductID
        SET     tmp.Status = 'New'
        WHERE   p.ProductID IS NULL
    

    By process of elimination, all other records in the temp table are “changed”. Once you have calculated the statuses, you can update the Products table:

        /*  update changed products */
        UPDATE Products p INNER JOIN Products_Temp tmp ON tmp.ProductID = p.ProductID
        SET    p.ProductName = tmp.ProductName
               , p.Stock = tmp.Stock
               , ...
               , p.DateLastChanged = now()
               , p.IsDiscontinued = 0
        WHERE  tmp.status = 'Changed'
    
        /*  insert new products */
        INSERT INTO Products ( ProductName, Stock, DateLastChanged, IsDiscontinued, .. )
        SELECT tmp.ProductName, tmp.Stock, now() AS DateLastChanged, 0 AS IsDiscontinued, ...
        FROM   Products_Temp tmp
        WHERE  tmp.Status = 'New'
    
        /* flag deleted records */
        UPDATE Products p LEFT JOIN Products_Temp tmp ON tmp.ProductID = p.ProductID
        SET    p.DateLastChanged = now()
               , p.IsDiscontinued = 1
        WHERE  tmp.ProductID IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all, sorry if that question is dumb but I´m a total newbie
First time posting here, will try to be succinct. This is a classic 'can't
First of all, I am sorry if this question doesn't belong to SO since
first question asked, so I'll get straight to it. I've got some C code
First let me phrase the proper question: Q: There is a file containing more
First let me say that I really feel directionless on this question. I am
First of all, I just installed XE2 for the first time, and plan to
First of all there is a question with the same title here on SO
First Im a noob in LINQ ! Then, the thing is that I have
First let me preface this question by saying that I'm fairly new to Javascript.

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.