I have been trying out the following query in MySQL Workbench:
SELECT NAME,LEAD,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,LEAD,OUTCOME ASC;
However I am getting this error:
"SELECT" is not valid at this position for this server version, expecting '(' with
I have tried to find out where the error is coming from by taking away parts of the query and seeing where it breaks, it seems to work when I try:
SELECT NAME
FROM OUTCOMES_BY_USER;
However when I add in another column (as shown below) I start getting the same error:
SELECT NAME, LEAD
FROM OUTCOMES_BY_USER;
I am really not sure how to get around this error, I was trying this query in sqlfiddle and it worked fine, however my sqlfiddle suddenly stopped working and the website just flat out wont build schemas for me anymore. so I tried it out on a my universities MySQL server and have been getting this error. Please help!
CodePudding user response:
LEAD() is a MySQL function, hence it is a reserved word. You can add backticks around reserved table or column names to bypass this error :
SELECT NAME,`LEAD`,OUTCOME,COUNT(*) AS NUMBER_OUTCOME
FROM OUTCOMES_BY_USER
ORDER by NAME,`LEAD`,OUTCOME ASC;