I am using load data infile, what would I have to do to import only a certaing element in CSV file to a certain column in our table
Asked
Active
Viewed 94 times
1 Answers
0
from the load-data page of mysql manual
LOAD DATA INFILE 'file.txt'
INTO TABLE t1
(column1, @dummy, column2, @dummy, column3);

Puggan Se
- 5,738
- 2
- 22
- 48
-
thanks for the fast reply, where I am getting confused is how to access columns of the loaded file , is there some index type of thing to do for example : SET column1(of mysql table) = column_5(of csv file) – Ranoy Jul 16 '12 at 12:43
-
1you have to load all columns from the csv, but the uninstresting values you store in @dummy (or just @d), so if you have 6 columns and you want the 5th to end up in the column `first_column`, you do `tablename (@d, @d, @d, @d, first_column, @d)` – Puggan Se Jul 16 '12 at 12:47
-
can you please tell me whats wrong with this sql LOAD DATA LOCAL INFILE 'C:/xampp/carandme/uploads/csv/e20dc61df48a313b4767cb9de9c35d3d.csv' INTO TABLE `on_road_price` (`city_id`, `city_name`,`state_name`,`item_id`, `ex_showroom`, `rto_charges`, `insurance_charges`, `octroi`, `other`, `price`)FIELDS TERMINATED BY ',' IGNORE 1 LINES (`city_id`, `city_name`,`state_name`, `ex_showroom`, `rto_charges`, `insurance_charges`, `octroi`, `other`, `price`) SET `item_id` ='18' – Ranoy Jun 10 '13 at 10:17
-
"(city_id"-part should only be in there once, keep the 2nd one, see http://dev.mysql.com/doc/refman/5.1/en/load-data.html for more details – Puggan Se Jun 10 '13 at 17:25