Mysql – Matching Custom Exported CSV File with Main MySQL Database

MySQL

I recently selected certain columns from a table from a huge MySQL db >10GB into a csv file and then filtered through the rows.

I would now like to retrieve the rest of the data matching the filtered rows. How could I go about doing that.

E.g.

MyTable (All columns are example names only)

+----+---------------+---------+-----------+
| ID | User          | Country | Etc..     |
+----+---------------+---------+-----------+
| 1  | JohnAppleSeed | Canada  | More Info |
+----+---------------+---------+-----------+
| 2  | ExampleUser   | Britain | More Info |
+----+---------------+---------+-----------+
| 3  | Admin         | Canada  | More Info |
+----+---------------+---------+-----------+

Exported.csv (unfiltered)

"JohnAppleSeed","Canada","More info"
"ExampleUser","Britain","More info"
"Admin","Canada","More info"

Exported.csv (filtered)

"JohnAppleSeed","Canada","More info"
"Admin","Canada","More info"

How do I get a file with the following information:

"1","JohnAppleSeed","Canada","More info"
"3","Admin","Canada","More info"

I know I could've selected columns where the value matched the country, but during the filtering process there were changes made to the 'more information' columns.

Best Answer

Load the Filtered output into a Temp table with columns User, Counter, ... Then do something like

SELECT ID, User, Country, ...
    INTO OUTFILE ...
    FROM MyTable AS m
    LEFT JOIN Temp AS t  ON USING(User, Country, ...)
    WHERE t.User IS NULL;