1

I've written a query and have filtered out the E.G "Salaries over $120,000."

I want to redirect the answer to a .csv file, however Im experiencing issues.

Ive read online that : To redirect the output of your queries to a file, append the following

clause to your queries:

INTO OUTFILE <filename> FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'

However: when I append this to my query...

SELECT from_date FROM dept_emp_latest_date WHERE from_date < '2002-08-01' and from_date > '2002-07-01' INTO OUTFILE new_hires.csv FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';

I just get a syntax error.

The query below works fine. But I need help to redirect it to my file... new_hires.csv.

SELECT from_date FROM dept_emp_latest_date WHERE from_date < '2002-08-01' and from_date > '2002-07-01'
Flimzy
  • 60,850
  • 13
  • 104
  • 147
Leslie Tate
  • 500
  • 1
  • 4
  • 15

1 Answers1

1

It looks like you need to put new_hires.csv inside single quotes ('new_hires.csv').

Also, I think the order of your statements needs to put the FROM and WHERE clauses at the end. Give this a try:

SELECT from_date INTO OUTFILE 'new_hires.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM dept_emp_latest_date
WHERE from_date < '2002-08-01' AND from_date > '2002-07-01';