Search code examples
mysqlmysql-error-1064

MySQL error 1064 when specifying a LIMIT


SELECT LEFT(c.user_notes, 200) AS user_notes, 
       c.TIME, 
       c.name 
FROM   saved s 
       INNER JOIN chimney c 
         ON c.id = s.can_id 
WHERE  s.user_id = 'admin' 
ORDER  BY lastmodified DESC 
LIMIT  ,10 

This statement gives me an error:

err#1064 - 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 '10' at line 1

How can this be solved?


Solution

  • Remove the , or use LIMIT 0, 10

    SELECT
      LEFT(c.user_notes,200) AS user_notes,
      c.time,
      c.name
    FROM saved s INNER JOIN chimney c ON c.id = s.can_id
    WHERE s.user_id='admin' 
    ORDER BY lastmodified DESC LIMIT 0, 10
    -------------------------------^^^^
    

    Note that 99% of the time, where MySQL complains of invalid syntax is exactly the place where the syntax error occurred.