开发者

Export a MySQL table via JOIN?

开发者 https://www.devze.com 2023-01-22 03:13 出处:网络
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?

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 wo开发者_运维百科uld 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;


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;


you can maybe use

 select into outfile
0

精彩评论

暂无评论...
验证码 换一张
取 消