Siddharth
Siddharth

Reputation: 9574

How to Select from into outfile csv with column names

I have looked at many SO questions, all of them provide a way for this by hardcoding the column names in the select call. But I need something for all column names.

SELECT * from deviceDetails, connectionDetails where deviceDetails.rowStatus='0' INTO OUTFILE '/tmp/devices.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

I need all the column names. Please help.

Upvotes: 1

Views: 1029

Answers (1)

albielin
albielin

Reputation: 590

If you don't mind tab-separated values, you can try this:

From the linux prompt,

mysql yourdb -B -e "
SELECT * from deviceDetails, connectionDetails where deviceDetails.rowStatus='0';
" > /path/to/file.tsv

The options mean: -B (batch) -e (execute)

Upvotes: 1

Related Questions