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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:31:57+00:00 2026-06-12T13:31:57+00:00

I have a MySQL table with several columns, including id and count . I

  • 0

I have a MySQL table with several columns, including id and count. I just got an Excel spreadsheet with the same item ids paired with numbers that must be added to the count for each row.

For instance, here’s a subset of the data, showing only the relevant columns:

| id  | count |
|-----+-------|
| ... | ...   |
| 348 | 165   |
| 347 | 364   |
| 346 | 381   |
| 345 | 6017  |
| ... | ...   |

And this the data from the Excel spreadsheet:

| id  | add   |
|-----+-------|
| ... | ...   |
| 348 | 3,766 |
| 347 | 386   |
| 346 | 860   |
| 345 | 0     |
| ... | ...   |

I want to combine the count and add fields for each id so that the count is updated like so, leaving all other columns in the table untouched:

| id  | count |
|-----+-------|
| ... | ...   |
| 348 | 3931  |
| 347 | 750   |
| 346 | 1241  |
| 345 | 6017  |
| ... | ...   |

I know MySQL can do it, but I don’t know what the steps are. What format should I export the Excel data? CSV? TSV? How do I read the “adjustment” file in to MySQL? What is the syntax for this kind of UPDATE command?

  • 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-12T13:31:59+00:00Added an answer on June 12, 2026 at 1:31 pm

    You’ll need to do this in a couple of steps:

    1. CREATE a TEMPORARY TABLE.
    2. LOAD the data into the temporary table
    3. UPDATE the original table, using a JOIN against the temporary one.

    CREATE [TEMPORARY] TABLE syntax is straightforward. It’s just like creating a table, but it goes away when your session ends. The table format should match the columns which you want to update. This can be accomplished simply using the CREATE ... (SELECT...) syntax, eg:

    CREATE TEMPORARY TABLE `data_to_load` (
        SELECT
            `id`,
            `count`
        FROM
            `table_to_update`
        WHERE
            0
    );
    

    This will create a TEMPORARY TABLE called data_to_load, consisting of exactly the same format as the table_to_update columns id and count. The WHERE 0 will never match, so it just copies the format of the table, not the data.

    Next, LOADing the data. The format isn’t picky, you just need to specify it. For standard CSV format as used by Excel, the command would be:

    LOAD DATA
        INFILE 'exported_data.csv'
        INTO TABLE `data_to_load`
        FIELDS
            TERMINATED BY ','
            OPTIONALLY ENCLOSED BY '"'
            ESCAPED BY '"'
    (
        `id`,
        `count`
    );
    

    Finally, UPDATE the existing data, by JOINing with your new table:

    UPDATE
        `table_to_update`
        INNER JOIN `data_to_load`
            ON `data_to_load`.`id` = `table_to_update`.`id`
    SET
        `table_to_update`.`count` = `table_to_update`.`count` + `data_to_load`.`count`
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails and MySQL: I have a table with several boolean columns representing tags. I
In a MySQL table, I have several columns - some containing strings, some dates
I have a mysql table that have several records linked to one particular tag.
I have several tables that get JOINed together to form a table with columns
Supose I have a table with several columns. I know how to find duplicates,
Lets say I have a table with just two columns: name and mood .
I have a mysql database table called character with columns like name, strength, intelligence,
I have a table which has several ID columns to other tables. I want
I have a MySQL table containing several fields; like this: id name ton dyr
I have a table with several hundred million rows. One of the columns is

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.