Nylo
Nylo

Reputation: 25

SQLSTATE[42000]: Syntax error or access violation: 1064. Cant find error in syntax

The following SQL statement worked on my job computer but not on my home one;

select 
    YEAR(FROM_UNIXTIME(UNIX_TIMESTAMP(time_created))) as year, 
    MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(time_created))) as month, 
    COUNT(id) as num 
FROM orders 
GROUP BY 
    YEAR(FROM_UNIXTIME(UNIX_TIMESTAMP(time_created))), 
    MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(time_created))) ASC
;

I fails with the error below;

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 'ASC' at line 1

What am I doing wrong and how can I fix it?

Upvotes: 0

Views: 1451

Answers (1)

Shadow
Shadow

Reputation: 34253

Mysql removed the asc and desc modifiers from the group by clause in v8.0. Your code was probabĺy created for an earlier version of mysql. If you check the mysql v5.7 documentation for the select syntax, the modifiers are still there.

You either need to remove the asc modifier or ensure that your code runs on a mysql version that still supports this synax.

Upvotes: 2

Related Questions