Re: Derby SQL ideas needed

2010-09-19 Thread Alexey Serba
SELECT DISTINCT ON (idbucket) t3.bucket AS idbucket, t3.activitycount AS activitycount, t3.windowstart AS starttime, t3.windowend AS endtime FROM (...) t3 Do you have primary key in your t3 table? In Postgresql, what this does is to return the FIRST entire row matching each distinct

Re: Derby SQL ideas needed

2010-09-19 Thread Alexey Serba
for these two queries (with distinct on hack and subquery max/subquery order limit/join) would be the same. I'd be happy to post it but it may shock you. ;-) The way I indent SQL queries should say that I'm not afraid of multipage queries :) Karl On Sun, Sep 19, 2010 at 11:32 AM, Alexey

Re: Derby SQL ideas needed

2010-09-19 Thread Alexey Serba
and not do it twice. Karl On Sun, Sep 19, 2010 at 12:05 PM, Alexey Serba ase...@gmail.com wrote: The other thing is that we cannot afford to use the same table twice, as it is actually an extremely expensive query in its own right, with multiple joins, select distinct's, etc. under the covers

Re: Derby SQL ideas needed

2010-09-19 Thread Alexey Serba
LIMIT yyy OFFSET zzz; I have low confidence that ANY planner would be able to locate the common part of a 2x larger query and not do it twice. Karl On Sun, Sep 19, 2010 at 12:05 PM, Alexey Serba ase...@gmail.com wrote: The other thing is that we cannot afford to use the same table twice