The syntax below, not entirely common, will create a comma separated file at the disk location indicated. The example below refers to a windows system, adapt as appropriate for other operating systems.
Double-click on the file and it will open in Excel or any other application associated with the .csv extension.
SELECT lname,fname,address,email INTO OUTFILE 'd:/CurrentCustomers.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM customers WHERE STATUS = 'current' ORDER BY lname,fname;
A dynamic outfile name is another idea, as this statement will not overwrite an existing outfile. Â An article on the Â MySQL discussion board covers this, and while it does not provide a perfect answer, is points in the direction of a solution involving the PREPARE statement.