I am new in sqlQuery so trying to creating a script. I have two table "FirstTable" and "secondTable". also having csv file. I am trying to create a sql script so that csv data will be copy in firstTable using secondTable Reference.
Rightnow i am trying to copy two csv column (LAT_HOLE, LONG_HOLE ) into FirstColumn. This is my FirstTable.
ID COURSEID HOLE LAT_HOLE LONG_HOLE
1 789 1
2 789 2
3 789 3
4 789 4
5 456 1
6 456 2
7 456 3
8 456 4
9 123 1
this is secondTable.
COUSRE_ID NAME
789 WEST
456 zoo
this is csv file format.
NAME LAT_HOLE LONG_HOLE
zoo 38.7204292 -77.01072156
Potomac 38.66841893 -76.96873426
your help would be greatful for me..
1 Create a new table named new_table that has similar structure of csv
LOAD DATA LOCAL INFILE 'filepath.csv' INTO TABLE new_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
2 update firsttable with this
update firsttable as f inner join
(
select t2.courseid,t1.lat_hole, t1.lot_hole from new_table as t1
inner join secondtable as t2 on t1.name=t2.name
) as t3 on f.courseid=t2.courseid
set
f.lat_hole=t3.lat_hole,
f.lon_hole=t3.lon_hole
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.