I have the following query and file and works fine.
Is it possible to do a subquery for product_id field (SELECT id FROM products where name = 'car') and how can I achieve that?
File:
postcode;huisnummer;toevoeging;product;datum
1775 BB;4;;CAR;02-01-2018
Query:
LOAD DATA LOCAL INFILE '$path'
INTO TABLE `temp_loc`
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
IGNORE 1 LINES
(@postcode,@huisnummer,@toevoeging,product,datum)
SET adres = CONCAT(REPLACE(@postcode, ' ', ''),'', @huisnummer,'$',@toevoeging);
Database columns:
merged_adres , product_id, datum
Answer:
LOAD DATA LOCAL INFILE '$path'
INTO TABLE `temp_loc`
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
IGNORE 1 LINES
(@postcode,@huisnummer,@toevoeging,@product,datum)
SET adres = CONCAT(REPLACE(@postcode, ' ', ''),'', @huisnummer,'$',@toevoeging),
product = (SELECT id FROM products WHERE name = @product);
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.