On Mon, Feb 15, 2016 at 2:05 PM, Simon Slavin <slavins at bigfraud.org> wrote:

>
> On 15 Feb 2016, at 8:58pm, James K. Lowden <jklowden at schemamania.org>
> wrote:
>
> > Clemens Ladisch <clemens at ladisch.de> wrote:
> >
> >> I don't know why correlated subqueries cannot use values from the
> >> outer query in the ORDER BY or LIMIT clauses;
> >
> > ORDER BY is not part of SELECT!  It's not a relational operator.
> > Per the SQL standard -- ORDER BY cannot appear in a subquery. It can
> > appear in only one place: as a kind of post-processor that determines
> > the order in which the rows are delivered to the client.
>
> And to build on that, if you cannot specify ORDER BY then you cannot
> expect LIMIT to do anything useful.  Since you don't know which ones will
> be top in the list there's no point in picking just the top ones.
>

I think there is still a potential use for limit (though maybe there's
another way I haven't considered). You have a table representing a job
queue. Each job will take some amount of time to process. The order doesn't
matter as long as all jobs are eventually processed and you have a single
process running the jobs. Limit 1 is a reasonable way to grab a single job.

-- 
Scott Robison

Reply via email to