0

Hi everyone I already know how to import a txt file to a database, But now I have two txt files with almost the same data on each file but the second file has one extra column and I dont need that column in my Db tables. The two .txt files has the followig structure:

FILE 1

"GTVLL2R","WG1032","10321","WG1032X","0","Band2","9316","9716","385","479","10321","79","1","279","0","CHIP0","10321","430","321","2","0","3","ACTIVATED","FALSE","-",""

"GTVLL2R","WG1032","10322","WG1032Y","0","Band2","9316","9716","393","479","10322","79","1","279","0","CHIP256","10322","430","330","2","0","3","ACTIVATED","FALSE","-",""

FILE 2

"GTCEN4R","208","WG1084","10841","WG1084X","0","Band2","9316","9716","282","511","10841","111","1","311","0","CHIP0","430","330","10841","ACTIVATED","FALSE","-",""

"GTCEN4R","208","WG1084","10842","WG1084Y","0","Band2","9316","9716","299","511","10842","111","1","311","0","CHIP256","430","330","10842","ACTIVATED","FALSE","-",""

"GTCEN4R","208","WG1084","10843","WG1084Z","0","Band2","9316","9716","53","511","10843","111","1","311","0","CHIP512","430","330","10843","ACTIVATED","FALSE","-",""

"GTCEN4R","208","WG1084","10844","WG1084U","0","Band2","9295","9695","282","511","10844","111","1","311","0","CHIP0","430","330","10844","ACTIVATED","FALSE","-",""

Specifically, I dont need the column with the number 208 on the second file (I have to clear up that isn't always the same number). I don't know how to ignore that column when I do the query, the query i'm using is the following:

LOAD DATA LOCAL INFILE  file_path INTO TABLE table_name
"FIELDS TERMINATED BY ',' 
"ENCLOSED BY '\"' 
"LINES TERMINATED BY '\\r\\n'
"IGNORE 2 LINES"

I would be very grateful If you can help me. Thanks

Community
  • 1
  • 1

1 Answers1

0

I assume you are asking because you want both files loaded into the same table. There is not a way to skip the column using LOAD DATA INFILE, but accomplishing what you are trying to do is doable.

Create table temp1 -- layout of first file

Load date infile from file 1 into temp1

Create table temp2 - layout of second file

Load data infile from file 2 into temp2

Alter table temp2 drop column 208_column

Create table combined_table like temp1

Insert into combined_table select * from temp1

Insert into combined_table select * from temp2
Bleach
  • 561
  • 4
  • 11