Tuesday, December 11, 2012

How to output MySQL query results in csv format

SELECT 'Order Id', 'Product Name', 'Quantity'
UNION
(
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE 'C:\\tmp\\orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
)

No comments:

Post a Comment