0

I am trying to output query result into a csv file

select*from  fileName INTO OUTFILE 'C:\\Users\\UserName\\Desktop\\ans.csv' 
columns terminated by ',' lines terminated by ',\n' ;

It is working fine but it is exporting the data I want to export data with attribute names.How to do that.

Example of EXPECTED OUTPUT I want data to be exported along with ID NAME AND CLASS.

 ID   NAME   CLASS
 1    AB     d3
 2    cc     d4
 3    ff     g8

What I am getting!1 
 1    AB     d3
 2    cc     d4
 3    ff     g8
Nurav
  • 167
  • 1
  • 3
  • 15

1 Answers1

0

Try this :

SELECT 'Name',
       'CLASS'
UNION ALL
SELECT Name,
       CLASS
FROM fileName INTO OUTFILE 'C:\\Users\\UserName\\Desktop\\ans.csv' columns terminated BY ',
                                                                                        ' lines terminated BY ',\n'