user965526
user965526

Reputation: 89

Separate Exports from a MYSQL query

I would like to create separate exported reports for the different types of animal I have in my table. I can write these reports separately, however I have over 200 different animal types and therefore running 200 separate queries is impractical.

ANIMAL_TABLE

    AnimalName
    -----------
    CAT 
    DOG
    MOUSE
    HORSE

I basically would like to run a similar query to

SELECT * INTO OUTFILE '/tmp/ANIMAL-NAME.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE 1

but have 4 CSV files instead of one, effectively every change in animal type creates a new file

CAT.csv 
DOG.csv
MOUSE.csv
HORSE.csv

Any help would be appreciated.

Upvotes: 1

Views: 53

Answers (1)

Johan
Johan

Reputation: 76537

SELECT * INTO OUTFILE '/tmp/ANIMAL-HORSE.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE animal_name LIKE 'horse'

Upvotes: 1

Related Questions