Connecting Tech Pros Worldwide Forums | Help | Site Map

LIMIT (Subquery)

Franc Walter
Guest
 
Posts: n/a
#1: Dec 11 '06
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


que
Guest
 
Posts: n/a
#2: Dec 12 '06

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 @cnt from tab2;
PREPARE STMT FROM 'SELECT * FROM tab1 LIMIT ?';
EXECUTE STMT USING @cnt;

Franc Walter wrote:
Quote:
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
Closed Thread