MySQL pagination query syntax error with LIMIT clause

I’m trying to set up pagination for results from my database using the LIMIT clause in MySQL, but I’m encountering a syntax error. The query runs well without the LIMIT part, but once I include it, the error appears.

SELECT 
  AppointmentData.DepartmentID, AppointmentData.ScheduledDate, AppointmentData.ScheduledTime,
  AppointmentData.AppointmentStatus, ClientInfo.GivenName, ClientInfo.FamilyName,
  ClientInfo.BirthDate
FROM AppointmentData
  LEFT JOIN ClientInfo
    ON AppointmentData.ClientID = ClientInfo.ClientID
WHERE ClientInfo.GivenName = 'John'
  AND ClientInfo.FamilyName = 'Smith'
  AND (AppointmentData.DepartmentID = '3' OR AppointmentData.DepartmentID = '4')
LIMIT '0, 15'
ORDER BY AppointmentData.ScheduledDate DESC

The error I receive is: #1064 - You have an error in your SQL syntax; check the manual for your MySQL server version regarding the correct syntax near ‘‘0, 15’ ORDER BY AppointmentData.ScheduledDate DESC’ at line 1.

Can someone help me identify the issue with my LIMIT clause? Any guidance would be greatly appreciated.

yep, those quotes are definetly messing things up. mysql needs numbers for LIMIT, not strings. also make sure the ORDER BY comes b4 LIMIT - basic sql rule. so it should be ORDER BY AppointmentData.ScheduledDate DESC LIMIT 0, 15 at the end.

The primary issue stems from two fundamental problems in your query structure. First, you have enclosed the LIMIT parameters in single quotes, which MySQL interprets as string literals rather than numeric values. The LIMIT clause requires integer values without quotation marks. Second, your ORDER BY clause must precede the LIMIT clause in MySQL syntax. The correct sequence should be: WHERE conditions, then ORDER BY, and finally LIMIT. Your corrected query should end with ORDER BY AppointmentData.ScheduledDate DESC LIMIT 0, 15. This ordering ensures MySQL first sorts your results by the scheduled date in descending order, then applies the pagination limit to return the first 15 records starting from offset 0.

oh wait, i think i see the issue - you’ve got quotes around your LIMIT values! try removing those quotes so it’s just LIMIT 0, 15 instead of LIMIT '0, 15'. also noticed your ORDER BY is after LIMIT which might cause problems too. what version of mysql are you running btw?