0
 LOAD DATA LOCAL INFILE 'hr.csv' INTO TABLE hr_analytics  FIELDS TERMINATED BY '`' IGNORE 1 LINES(NO,SATISFACTION_LEVEL,LAST_EVALUATION,NUMBER_PROJECT,AVERAGE_MONTLY_HOURS,TIME_SPEND_COMPANY,WORK_ACCIDENT,LEFT,PROMOTION_LAST_5YEARS,SALES,SALARY)

when i run above query i get:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT,PROMOTION_LAST_5YEARS,SALES,SALARY)' at line 1

how to solve this?

2 Answers 2

1

The problem seems to be that LEFT is a MySQL key word. Try this:

LOAD DATA LOCAL INFILE 'hr.csv' INTO TABLE hr_analytics  FIELDS TERMINATED BY '`' IGNORE 1 LINES(`NO`,`SATISFACTION_LEVEL`,`LAST_EVALUATION`,`NUMBER_PROJECT`,`AVERAGE_MONTLY_HOURS`,`TIME_SPEND_COMPANY`,`WORK_ACCIDENT`,`LEFT`,`PROMOTION_LAST_5YEARS`,`SALES`,`SALARY`)
Sign up to request clarification or add additional context in comments.

3 Comments

i have already ran the query and i got com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'NO' in 'field list'
Please post the table definition and the first 2 or 3 lines (anonymized!) of the CSV!
Try using different quotes in lines as the identifier quote character is the backtick. Otherwise MySQL "thinks" that you point to a columns. Try this : LOAD DATA LOCAL INFILE 'hr.csv' INTO TABLE hr_analytics FIELDS TERMINATED BY '`' IGNORE 1 LINES('NO','SATISFACTION_LEVEL','LAST_EVALUATION','NUMBER_PROJECT','AVERAGE_MONTLY_HOURS','TIME_SPEND_COMPANY','WORK_ACCIDENT','LEFT','PROMOTION_LAST_5YEARS','SALES','SALARY')
0

You have a problem because you use a reserved SQL word 'LEFT'.

If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

The identifier quote character is the backtick "`".

1 Comment

1LOAD DATA LOCAL INFILE 'hr.csv' INTO TABLE hr_analytics FIELDS TERMINATED BY '' IGNORE 1 LINES(NO,SATISFACTION_LEVEL,LAST_EVALUATION,NUMBER_PROJECT,AVERAGE_MONTLY_HOURS,TIME_SPEND_COMPANY,WORK_ACCIDENT,LEFT,PROMOTION_LAST_5YEARS,SALES,SALARY) when i run the above query i get Unknown column 'NO' in 'field list'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.