C.R.Vegelin wrote:
Thanks JR, Shawn, Scott, ... for your replies.
I choose to make use of the SELECT ... INTO OUTFILE.
This works fine, but I also want a header-line in the CSV file.
So I made the following statement:
SELECT `ID`, `Code`, `Name`
UNION
SELECT `ID`, `Code`, `Name` INTO OUTFILE 'D:/MySQL Datafiles/Units.csv'
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'
FROM Units ORDER BY `ID`;
But this makes the header-line a trailer-line in the csv file, like this:
11,kg,KiloGrams
12,g,Grams
13,Ton,Tonne
...
ID,Code,Name
Any idea how to make a sorted csv file with a real header-line ?
TIA, Cor
I suspect your query is treated as
(SELECT `ID`, `Code`, `Name`)
UNION
(SELECT `ID`, `Code`, `Name` INTO OUTFILE 'D:/MySQL Datafiles/Units.csv'
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' FROM Units )
ORDER BY `ID`;
when you want
(SELECT `ID`, `Code`, `Name`)
UNION
(SELECT `ID`, `Code`, `Name` INTO OUTFILE 'D:/MySQL Datafiles/Units.csv'
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'
FROM Units ORDER BY `ID`);
You see the difference? The former sorts all the rows by id, while the latter
only sorts the second query's output.
Michael
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]