"Bessares, Bob" <[EMAIL PROTECTED]> wrote: > Hello MYSQL Genii, > I am trying to run a query that returns results to a .csv file using mysql's 'INTO > OUTFILE'. > The problem is whenever I write the file I lose my the field names for each > column. For example, when I run the query at command line mysql: > mysql> SELECT distinct count(*), Product FROM LIVE WHERE dbStatus = 'Live' and > vertical = 'Cars' GROUP BY Product;^MI get this: > +----------+---------+^M| count(*) | Product |^M+----------+---------+^M| 4 | > BANN |^M| 10 | CRBN |^M| 256 | LEAD |^M| 36 | SALE |^M| > 26 | TRBN |^M+----------+---------+^M5 rows in set (0.20 sec) > > I want to have the titles of my columns (like above) in my .csv file... > When I use the 'INTO OUTFILE' syntax I lose all of the titles and just get the data > returned like this: > > 4,"BANN"^M10,"CRBN"^M256,"LEAD"^M36,"SALE"^M26,"TRBN" > Is it possible to use INTO OUTFILE and still get my field names outputted?
No, SELECT INTO OUTFILE doesn't include column names to the file. You should do it by yourself. > Here is the query $var I am using for perl or php. > $query = "SELECT distinct count(*), Product FROM LIVE WHERE dbStatus = 'Live' and > vertical = 'Cars' GROUP BY Product INTO OUTFILE > '/www/vhosts/someurl.org/htdocs/report_files/apts_mnth_unit.csv' FIELDS TERMINATED > BY '\,' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"; > -- For technical support contracts, goto https://order.mysql.com/?ref=ensita This email is sponsored by Ensita.net http://www.ensita.net/ __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Egor Egorov / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net <___/ www.mysql.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]