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.


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.

  • Is the information in the CSV row (user-country combination) enough to uniquely identify the needed row? If it is not then you should have kept the ID in there. If it is, you can import the data into a temporary table and do a simple join.
    – jkavalik
    Jun 17, 2016 at 18:23
  • Yea, it is enough to uniquely identify the needed row. Thanks for pointing out 'join' didnt think about that before
    – Hades
    Jun 18, 2016 at 2:24

1 Answer 1


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

SELECT ID, User, Country, ...
    FROM MyTable AS m
    LEFT JOIN Temp AS t  ON USING(User, Country, ...)
    WHERE t.User IS NULL;
  • Yea, thats what i did. It worked out fine.
    – Hades
    Jul 5, 2016 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.