[sqlite] Correlated subquery throwing an error

2016-02-16 Thread James K. Lowden
On Mon, 15 Feb 2016 14:19:12 -0700 Scott Robison wrote: > 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. Reasonable,

[sqlite] Correlated subquery throwing an error

2016-02-16 Thread James K. Lowden
On Mon, 15 Feb 2016 14:55:34 -0700 "Keith Medcalf" wrote: > Pretty sure you meant: > > select * from (select min(t) as t from T) as T; Yes, thanks. :-) --jkl

[sqlite] Correlated subquery throwing an error

2016-02-16 Thread Scott Robison
On Tue, Feb 16, 2016 at 11:44 AM, James K. Lowden wrote: > On Mon, 15 Feb 2016 14:19:12 -0700 > Scott Robison wrote: > > > 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

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread da...@andl.org
age- From: sqlite-users-boun...@mailinglists.sqlite.org [mailto:sqlite-users-bounces at mailinglists.sqlite.org] On Behalf Of Gary Briggs Sent: Monday, 15 February 2016 11:47 AM To: SQLite mailing list Subject: Re: [sqlite] Correlated subquery throwing an error On Mon, Feb 15, 2016 at 11:11:26AM +1

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Simon Slavin
On 15 Feb 2016, at 8:58pm, James K. Lowden wrote: > Clemens Ladisch 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 --

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread James K. Lowden
On Mon, 15 Feb 2016 08:56:35 +0100 Clemens Ladisch 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

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread James K. Lowden
On Mon, 15 Feb 2016 10:39:31 +0100 Clemens Ladisch wrote: > > you need to explicitly limit a subquery that is a field and must > > only ever return 1 result if the where clause is ambiguous about it > > Not in SQLite. (It ignores superfluous rows, and returns NULL if > there are no rows.)

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Dan Kennedy
On 02/15/2016 02:56 PM, Clemens Ladisch wrote: > Gary Briggs wrote: >>> SELECT >>>a.id AS a_id, >>>(SELECT b.id >>> FROM foo AS b >>> WHERE b.id!=a.id >>> AND distance(a.x,a.y,b.x,b.y)<=25 >>> ORDER BY b.val, distance(a.x,a.y,b.x,b.y)) >>> FROM foo AS a >> This is the bit

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Keith Medcalf
sqlite] Correlated subquery throwing an error > > On Mon, 15 Feb 2016 10:39:31 +0100 > Clemens Ladisch wrote: > > > > you need to explicitly limit a subquery that is a field and must > > > only ever return 1 result if the where clause is ambiguous about it > > > &g

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Scott Robison
On Mon, Feb 15, 2016 at 2:05 PM, Simon Slavin wrote: > > On 15 Feb 2016, at 8:58pm, James K. Lowden > wrote: > > > Clemens Ladisch 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

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Gary Briggs
On Mon, Feb 15, 2016 at 08:56:35AM +0100, Clemens Ladisch wrote: > Gary Briggs wrote: > >> SELECT > >> a.id AS a_id, > >> (SELECT b.id > >>FROM foo AS b > >>WHERE b.id!=a.id > >> AND distance(a.x,a.y,b.x,b.y)<=25 > >>ORDER BY b.val, distance(a.x,a.y,b.x,b.y)) > >> FROM foo AS

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread da...@andl.org
oun...@mailinglists.sqlite.org [mailto:sqlite-users-bounces at mailinglists.sqlite.org] On Behalf Of Gary Briggs Sent: Monday, 15 February 2016 10:43 AM To: sqlite-users at mailinglists.sqlite.org Subject: [sqlite] Correlated subquery throwing an error I posted a question on stackoverflow, here: h

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Clemens Ladisch
R Smith wrote: > you need to alias a subquery always when it is used in a join Not in SQLite. > you need to explicitly limit a subquery that is a field and must only > ever return 1 result if the where clause is ambiguous about it Not in SQLite. (It ignores superfluous rows, and returns NULL

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread R Smith
On 2016/02/15 3:01 AM, Gary Briggs wrote: > > This is the bit that doesn't seem to work; having > distance(a.x,a.y,b.x,b.y) in the ORDER BY clause on the inner query is > what appears to cause the error that it can't find a.x, from the outer query. > > It's not tied to it being a custom

[sqlite] Correlated subquery throwing an error

2016-02-15 Thread Clemens Ladisch
Gary Briggs wrote: >> SELECT >> a.id AS a_id, >> (SELECT b.id >>FROM foo AS b >>WHERE b.id!=a.id >> AND distance(a.x,a.y,b.x,b.y)<=25 >>ORDER BY b.val, distance(a.x,a.y,b.x,b.y)) >> FROM foo AS a > > This is the bit that doesn't seem to work; having > distance(a.x,a.y,b.x,b.y)

[sqlite] Correlated subquery throwing an error

2016-02-14 Thread Gary Briggs
On Sun, Feb 14, 2016 at 07:31:43PM -0500, Richard Hipp wrote: > On 2/14/16, Gary Briggs wrote: > > > > "For every row in that table, I want the entire row in that same table > > within a certain distance [eg 25], with the lowest "val". For rows > > with the same "val", I want to use lowest

[sqlite] Correlated subquery throwing an error

2016-02-14 Thread Gary Briggs
> [mailto:sqlite-users-bounces at mailinglists.sqlite.org] On Behalf Of Gary > Briggs > Sent: Monday, 15 February 2016 10:43 AM > To: sqlite-users at mailinglists.sqlite.org > Subject: [sqlite] Correlated subquery throwing an error > > I posted a question on stackoverflow, here:

[sqlite] Correlated subquery throwing an error

2016-02-14 Thread Richard Hipp
On 2/14/16, Gary Briggs wrote: > > "For every row in that table, I want the entire row in that same table > within a certain distance [eg 25], with the lowest "val". For rows > with the same "val", I want to use lowest distance as a tie breaker." > Untested code follows. I'l build up the answer

[sqlite] Correlated subquery throwing an error

2016-02-14 Thread Gary Briggs
I posted a question on stackoverflow, here: http://stackoverflow.com/questions/35382897/implementing-a-sql-query-without-window-functions In short, I have a table that I'm trying to query: CREATE TABLE foo ( id INTEGER PRIMARY KEY, x REAL NOT NULL, y REAL NOT NULL, val REAL NOT NULL,