0

EXAMPLE:

CREATE TABLE t (A INT);
INSERT INTO t VALUES(1),(2),(3),(4),(5);

This works:

SELECT A FROM t WHERE A=(SELECT 1)

This does not:

SELECT A FROM t LIMIT (SELECT 1);

This works:

SELECT A FROM t WHERE A=substring((SELECT 123),1,1);

This does not:

SELECT A FROM t WHERE A=1 PROCEDURE ANALYSE((SELECT 1),10000);

What makes some clauses and functions support SELECT statements and others not support it. I would think that running (SELECT 1) returns a 1 as a parameter and as long as the parameter is the expected type it should work. This seems to be true in some cases, but not others. Why is that?

  • 1
    Suppose someone from the original MySQL architecture team comes here and explains at length why they chose to implement it this way; what will it change? – mustaccio Nov 16 '19 at 1:47
0

this is the way LIMIT can be done in MySQL using variable parameters:

SET @skip=1; SET @numrows=5;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?, ?';
EXECUTE STMT USING @skip, @numrows;

In the place where it says SET @skip=1, One can also write SET @skip=(SELECT 1).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.