LIMIT (Subquery)
Hello,
i didn't find it in the help, i think it is not possible, but i try to
question anyway:
Is the MySQL command "LIMIT" possible with a subquery in MySQL 4.0.27?
e.g.: SELECT * FROM tab1 LIMIT (SELECT COUNT(*) from tab2)
this doesn't work.
MySQL 5.1 writes:
User variables may be used in contexts where expressions are allowed.
This does not currently include contexts that explicitly require a
literal value, such as in the LIMIT clause of a SELECT statement, or
the IGNORE N LINES clause of a LOAD DATA statement...
Is there a workaround?
franc
Re: LIMIT (Subquery)
I don't think its good idea at all.
Anyway take a look at prepared statements (support added in 5.0.7)
SELECT COUNT(*) into [at] cnt from tab2;
PREPARE STMT FROM 'SELECT * FROM tab1 LIMIT ?';
EXECUTE STMT USING [at] cnt;
Franc Walter wrote:
> Hello,
> i didn't find it in the help, i think it is not possible, but i try to
> question anyway:
> Is the MySQL command "LIMIT" possible with a subquery in MySQL 4.0.27?
>
> e.g.: SELECT * FROM tab1 LIMIT (SELECT COUNT(*) from tab2)
>
> this doesn't work.
> MySQL 5.1 writes:
> User variables may be used in contexts where expressions are allowed.
> This does not currently include contexts that explicitly require a
> literal value, such as in the LIMIT clause of a SELECT statement, or
> the IGNORE N LINES clause of a LOAD DATA statement...
>
> Is there a workaround?
> franc