Not a bug. The *expression* following `LIMIT` must be a *constant expression*. That is it must be able to be evaluated **before** the statement to which the limit applies (and must not change during execution) and therefore must not be dependent on data items contained within the query of which it is a part. Note sure if this is documented but this is how `limit` works.