Is it possible for me to write an SQL query from within PhpMyAdmin that will search for matching records from a .csv file and match them to a table in MySQL?
Basically I want to do a WHERE IN query, but I want the WHERE IN to check records in a .csv file on my local machine, not a column in the database.
Can I do this?
Upvotes: 1
Views: 9891
Reputation: 366
For anyone new asking, there is this new tool that i used : Write SQL on CSV file
Upvotes: 0
Reputation: 10538
I would do the following:
LOAD DATA INFILE
commandThere is no way to have the CSV file on the client and the table on the server and be able to compare the contents of both using only SQL.
Upvotes: 2
Reputation: 40675
I'd load the .csv content into a new table, do the comparison/merge and drop the table again. Loading .csv files into mysql tables is easy:
LOAD DATA INFILE 'path/to/industries.csv'
INTO TABLE `industries`
FIELDS TERMINATED BY ';'
IGNORE 1 LINES (`nogaCode`, `title`);
There are a lot more things you can tell the LOAD command, like what char wraps the entries, etc.
Upvotes: 6
Reputation: 513
Short answer: no, you can't.
Long answer: you'll need to build a query locally, maybe with a script (Python/PHP) or just uploading the CSV in a table and doing a JOIN
query (or just the WHERE x IN(SELECT y FROM mytmmpTABLE...)
)
Upvotes: 1