LIMIT (Subquery)
am 11.12.2006 17:18:02 von francwalter
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)
am 12.12.2006 13:38:57 von que
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 @cnt from tab2;
PREPARE STMT FROM 'SELECT * FROM tab1 LIMIT ?';
EXECUTE STMT USING @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