2010-10-25 76 views
1

我想知道如果不是創建另一個表來存儲MySQL JOIN查詢的結果是否可以只導出查詢結果,如CSV?通過JOIN導出MySQL表?

例如查詢會是這樣的..

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; 

回答

5

燁;

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; 
+0

方式更果斷:) – Orbit 2010-10-25 19:34:48

+0

+1:由35秒打我 - 這裏的[鏈接到文件(http://dev.mysql.com/doc/refman/5.0/en/select。 html) – 2010-10-25 19:35:51

+0

非常感謝! :) – Brett 2010-10-25 19:36:49

0

你也許可以使用

select into outfile