tags:

views:

36

answers:

2

I uploaded a csv file to MySQL DB but for some reason data from two columns got glued to one.

e.g. the data 0880174V,D should have gone to two different columns.

Is there a way (via sql) i can split the data from this column (i.e. as 0880174V and D) and update the table, without having to delete the record and re-upload? I have a million records.

==CURRENT

Column A       Column B
0880174V,D     

== EXPECTED

Column A       Column B
0880174V        D   
+4  A: 
UPDATE my_table
SET ColumnB = SUBSTRING(ColumnA, INSTR(ColumnA, ',') + 1),
    ColumnA = SUBSTRING(ColumnA, 1, INSTR(ColumnA, ',') - 1)

Do a SELECT TOP first to ease your mind.

smink
Bah humbug - too slow
Romain Hippeau
Thank you very much. Although it kind of did the reverse (D 0880174V) instead of (0880174V D), i got the insight. Appreciate your help.
Kushal Paudyal
Yap, you are right. Sorry, my bad. Changed the answer in any case. Is late in my time zone, if that is to any aval :)
smink
+1  A: 

You have to specify field terminator

load data local infile 'file.csv' into myTable
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(col1,col2)

EDIT: nvm

Imre L