Home > front end >  SQL syntax Error using SELECT, ORDER BY, ASC, and LIMIT
SQL syntax Error using SELECT, ORDER BY, ASC, and LIMIT

Time:07-12

SELECT SQL_CALC_FOUND_ROWS 
FROM personas 
ORDER BY nombre ASC 
LIMIT 0, 10;

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 'FROM personas ORDER BY nombre ASC LIMIT 0, 10' at line 2.

Hi, I'm new in MySQL and I have this error. I don't really understand what's wrong here.

CodePudding user response:

  1. In case you are using MySQL 8.0.17 or higher version

The SQL_CALC_FOUND_ROWS query modifier and accompanying FOUND_ROWS() function are deprecated as of MySQL 8.0.17; expect them to be removed in a future version of MySQL. As a replacement, considering executing your query with LIMIT, and then a second query with COUNT(*) and without LIMIT to determine whether there are additional rows. For example, instead of these queries:

SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name WHERE id > 100 LIMIT 10;
SELECT FOUND_ROWS();

Use these queries instead:

SELECT * FROM tbl_name WHERE id > 100 LIMIT 10;
SELECT COUNT(*) FROM tbl_name WHERE id > 100;
  1. MySQL older version I am correcting your SQL statement

    SELECT SQL_CALC_FOUND_ROWS * FROM personas ORDER BY nombre ASC LIMIT 0, 10;

  • Related