0

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.

  • 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 '16 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 '16 at 2:24
0

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;
  • Yea, thats what i did. It worked out fine. – Hades Jul 5 '16 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.