SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dumping Query Results

    Hi all,

    Is there a way I can dump only the result of a given query instead of a whole table?

    Thanks

    Tryst

  2. #2
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tryst
    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.

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're just wanting the data, and not the sql statements then something like this...
    Code:
    SELECT 
    	lastname, preferred 
    INTO OUTFILE 
    	'employeedata.csv'
    FIELDS TERMINATED BY ','
    FROM 
    	`contacts` 
    WHERE
    	employeeid > 8009900
    AND
    	employeeid < 8009999
    The result is a comma separated file with just the lastname and firstname.
    Lats...

  5. #5
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lats - Ideally, i'd like to have the SQL commands as well :s

    Is there such a method that allows this?

    Tryst

  6. #6
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...
    Code:
    INSERT INTO 
    	contacts_filtered
    SELECT 
    	lastname, preferred 
    FROM 
    	contacts 
    WHERE
    	employeeid > 8009900
    AND
    	employeeid < 8009999
    From there, you can do a regular mysqldump on the new table.
    Lats...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •