i use this query but it not show the column name
SELECT * FROM employeemaster INTO OUTFILE 'c:/order-1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
i use this query but it not show the column name
SELECT * FROM employeemaster INTO OUTFILE 'c:/order-1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Use the below query:
SELECT empid as employeeid,sname as staffname FROM employeemaster INTO
OUTFILE 'c:/order.csv' FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
There are two possible solutions:
The simple one : hardcode the colum names yourself and join the header line with the query result :
SELECT 'Name_I_Want_For_Col1', 'Name_I_Want_For_Col1', 'Name_I_Want_For_Col1'
UNION ALL
SELECT ColName1, ColName2, ColName3
FROM YourTable
INTO OUTFILE '/path/outfile'
A more straight forward (but more complex one) : Get the colum names from information schema :
select GROUP_CONCAT(CONCAT("'",COLUMN_NAME,"'"))
from INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'my_table'
AND TABLE_SCHEMA = 'my_schema'
order BY ORDINAL_POSITION
UNION ALL
SELECT ColName1, ColName2, ColName3
FROM YourTable
INTO OUTFILE '/path/outfile'