Re: [GENERAL] subquery join order by

2010-11-19 Thread Mage
I considered this, however the subquery is generated by an ORM. I wanted to separate it. Also the whole join affects many rows. I thought it's cheaper to preselect them inside the subquery then do the join. I am not sure. Explain analyze is my good friend but in this case I prefer to ask. #

Re: [GENERAL] subquery join order by

2010-11-19 Thread Mage
On 11/19/2010 03:21 AM, Thom Brown wrote: You should always use ORDER BY on the outer-most part of the query since that's what will be finally returning your data. Don't bother with ordering sub-selects. I definiatelly have to use the "order by" inside for two reasons. When "distinct on (x)"

Re: [GENERAL] subquery join order by

2010-11-18 Thread Thom Brown
On 19 November 2010 01:36, Mage wrote: >            Hello, > > (I googled and read docs before sending this e-mail). > > Is it necessary to use order by twice (inside and outside) to get the proper > order if I have an ordered subqery in a join? > > select * from (select distinct on (b_id) * from

[GENERAL] subquery join order by

2010-11-18 Thread Mage
Hello, (I googled and read docs before sending this e-mail). Is it necessary to use order by twice (inside and outside) to get the proper order if I have an ordered subqery in a join? select * from (select distinct on (b_id) * from a order by b_id, id) sub left join b on b.id = s