>>>>> "Paul" == Paul DuBois <paul@stripped> writes:
Paul> At 9:53 AM +1100 2000-01-10, Albert Ng wrote:
>> Thanks Paul.
>>
>> Well I was hoping that I can use variables to
>> find the size of a table so that I can display only
>> the last few rows of the table by using limit since
>> I can't do a limit -10 to signify I want it to go from
>> the bottom of the records. And without sub-query,
>> looks like my only choice is to do 2 sql's and
>> use a local variable in my program. sigh....oh,
>> I can't upgrade to 3.23 for various reasons.
Paul> Well, I just tried doing what you want to do under 3.23.8,
Paul> and it doesn't appear to be possible anyway. I tried
Paul> setting a variable to the number of rows in a table like this:
Paul> SELECT @a:=COUNT(*) FROM tbl_name;
Paul> That worked. Then I tried getting the last few rows like this:
Paul> SELECT * FROM tbl_name LIMIT @a-10, 10;
Paul> That didn't work (syntax error at '@a').
Paul> Then I tried setting @a directly with a SET @a:=num statement,
Paul> followed by:
Paul> SELECT * FROM tbl_name LIMIT @a, 10;
Paul> Still get a syntax error at '@a'.
Paul> So my question is: in what contexts can you use user variables.
Paul> In a SET statement, clearly. Also in the selection list for a
Paul> SELECT statement. And I've been able to use them in the WHERE
Paul> clause as well. But what are the actual rules governing where you
Paul> can use them?
Hi!
You can use variables in all cases where mysqld doesn't currently
force you to use an integer (like in LIMIT).
I have added to the TODO to allow variables with LIMIT.
Regards,
Monty