Hi all,
Is there a way I can dump only the result of a given query instead of a whole table?
Thanks
Tryst
| SitePoint Sponsor |





Hi all,
Is there a way I can dump only the result of a given query instead of a whole table?
Thanks
Tryst



Please explain further.Originally Posted by Tryst





OK.
There is a function in MySQL called mysqldump that allows you to dump the contents of a whole database, or specific tables to a .sql file. I was wondering if there is a way that you can dump only a majority of the contents of a table (not all).
I assume this can't be done through the mysqldump command, but was wondering if there is some form of query that allows me to do this.
Hope that clarifies things a little
Cheers
Tryst





If you're just wanting the data, and not the sql statements then something like this...The result is a comma separated file with just the lastname and firstname.Code:SELECT lastname, preferred INTO OUTFILE 'employeedata.csv' FIELDS TERMINATED BY ',' FROM `contacts` WHERE employeeid > 8009900 AND employeeid < 8009999
Lats...





Lats - Ideally, i'd like to have the SQL commands as well :s
Is there such a method that allows this?
Tryst





Okay, here's a work-a-round
As an example, create a new table with 2 fields lastname & firstname, I've called it contacts_filtered and use this...From there, you can do a regular mysqldump on the new table.Code:INSERT INTO contacts_filtered SELECT lastname, preferred FROM contacts WHERE employeeid > 8009900 AND employeeid < 8009999
Lats...
Bookmarks