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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:58:43+00:00 2026-05-19T09:58:43+00:00

I have two CSV files, each containing different columns that I want to merge

  • 0

I have two CSV files, each containing different columns that I want to merge into one database. I set up a database with all the columns from both files, but when I use load data infile to import both files instead of merging (IE data file 1 fills columns 1-6, data file 2 fills 7-10) I get a database with twice as many rows (one row for each record in each CSV) and NULLS filling in the data not represented in the source CSV.

I know I can fix this by merging the CSVs somehow, importing with overwrite enabled, or combining the data in the database – what’s the most efficient way for me to do this?

  • 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-19T09:58:44+00:00Added an answer on May 19, 2026 at 9:58 am

    The best way to do this is with a script. CSV import scripts are usually written in a scripting language such as python, ruby, or php.

    You just need the importer for the second CSV to perform updates on the records created in the first CSV, so the script will really only be 5-10 lines. If you provide a sample record from each CSV, I’d be happy to write one for you.

    Edit: Here’s a python script to combine the files, adding a semicolon between lines from file1 and lines from file2. This essentially does what Linux’s paste command would do.

    lines1 = open('file1.txt').readlines()
    lines2 = open('file2.txt').readlines()
    outfile = open('outfile.txt', 'w')
    
    if len(lines1) != len(lines2):
        raise Exception("Files need to be the same length, but file1 is %s lines long and file2 is %s lines long" % (len(lines1), len(lines2)));
    
    for i in range(len(lines1)):
        combined = lines1[i].strip() + ";" + lines2[i].strip() + "\n"
        outfile.write(combined)
    

    You can run it by saving it as combine.py and typing python combine.py. The folder you place it in should contain file1.txt, file2.txt, and outfile.txt.

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

Sidebar

Related Questions

I have tried the merge function to merge two csv files that I imported.
I have two .csv files containing correlation matrices exported from R. One file contains
I have two tab delimited csv files (with headers) that I need to merge
I have a script that reads two csv files and compares them to find
I have 1000 CSV files from dfr.jstor.org with two columns, KEYWORDS and WEIGHT. The
I have two csv files: one is 98 mb and the other one is
I have two DataTables, A and B , produced from CSV files. I need
I have two applications written in Java that communicate with each other using XML
I have two classes, and want to include a static instance of one class
I have a list of csv files ( file1, file2, ... ) that have

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.