views:

36

answers:

2

Hey guys..... I was wondering if rather than creating another table to store the results of the MySQL JOIN query is it possible to just export a queries result.... like to a CSV?

The query for example would be something like this..

SELECT 
    us.id,
    CONCAT_WS(' - ',cats_sic_us.sic,cats_sic_us.category) AS sic_cat
FROM
    us
    INNER JOIN cats_sic_us ON us.sic=cats_sic_us.id;

Thanks a lot!

A: 

you can maybe use

 select into outfile
Orbit
+3  A: 

Yup;

SELECT 
    us.id,
    CONCAT_WS(' - ',cats_sic_us.sic,cats_sic_us.category) AS sic_cat
INTO OUTFILE '/tmp/results.csv'
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
FROM
    us
    INNER JOIN cats_sic_us ON us.sic=cats_sic_us.id;
Björn
way more decisive :)
Orbit
+1: Beat me by 35 seconds - here's the [link to the documentation](http://dev.mysql.com/doc/refman/5.0/en/select.html)
OMG Ponies
Thank you very much! :)
Brett
Any reason why adding a FIELDS ESCAPED BY '\\' causes an error?
Brett
Provide the full line! If you're already defining "FIELDS TERMINATED BY..." you should remove the "FIELDS" keyword: "FIELDS TERMINATED BY ',' ESCAPED BY '\\'..."
Björn
That fixed it... thanks! Had multiple "FIELDS" in there.
Brett