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;
I get this:
+----------+---------+
| count(*) | Product |
+----------+---------+
| 4 | BANN |
| 10 | CRBN |
| 256 | LEAD |
| 36 | SALE |
| 26 | TRBN |
+----------+---------+
5 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"
10,"CRBN"
256,"LEAD"
36,"SALE"
26,"TRBN"
Is it possible to use INTO OUTFILE and still get my field names outputted?
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'";
If anyone of you geeks, I mean genii, can assist, I would be happy to name my first
born in your honor.
TIA!
\\\|///
\\ ~ ~ //
(/ @ @ /)
+------------oOOo-(_)-oOOo----------+
| Bob Bessares |
| latimes.com |
| 202 West 1st Street |
| Los Angeles, CA 90012 |
| Phone : (213) 473-2505 |
| Fax : (213) 473-2438 |
| e-mail: [EMAIL PROTECTED] |
+-----------------------------------+
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]