According to the reference manual :
The LIMIT
clause can be used to constrain the number of rows
returned by the SELECT statement. LIMIT
takes one or two numeric
arguments , which must both be nonnegative integer constants, with
these exceptions:
-
Within prepared statements, LIMIT parameters can be specified using? placeholder markers.
-
Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.
Quickly translated: it only supports numerical values directly, except for two exceptions: in prepared queries, you can use a dynamic marker. Or use a stored procedure, where it would admit, a local variable.
Let's apply both solutions:
Prepared inquiry
SET @limitTwo=(SELECT COUNT(*) FROM TABLA1);
PREPARE STMT FROM 'SELECT * FROM PERSONA LIMIT O,?';
EXECUTE STMT USING @limitTwo;
Stored procedure
CREATE PROCEDURE customLimit()
BEGIN
DECLARE limitTwo INT DEFAULT 1;
SET limitTwo = (SELECT COUNT(*) FROM TABLA1) ;
SELECT * FROM PERSONA LIMIT 0,limitTwo;
END;
We call it to show the data:
CALL customLimit();