[GENERAL] Subselect Question

2004-11-02 Thread Alex P
Hi, when creating a query with a subselect SELECT name, (SELECT max(pop) FROM cities WHERE cities.state = states.name) AS max_pop FROM states; then it is not possible to sort after max_pop or use max_pop in a function or a CASE. am I dont anything wrong or is this meant to be the case? Thanks Al

Re: [GENERAL] Subselect Question

2004-11-02 Thread Tino Wildenhain
Hi, On Tue, 2004-11-02 at 09:05, Alex P wrote: > Hi, > > when creating a query with a subselect > > SELECT name, (SELECT max(pop) FROM cities WHERE cities.state = states.name) AS > max_pop > FROM states; > > then it is not possible to sort after max_pop or use max_pop in a function or a CA

Re: [GENERAL] Subselect Question

2004-11-02 Thread Sim Zacks
You can't use the alias name in the sort, case, where etc.. you have to use the entire subselect. So you would order by (select max(pop)...) and you would also case the full thing as well. A bit of a pain but Tom Lane explained it in a post a couple days ago and said the system was optimized so it

Re: [GENERAL] Subselect Question

2004-11-02 Thread Richard Huxton
Alex P wrote: Hi, when creating a query with a subselect SELECT name, (SELECT max(pop) FROM cities WHERE cities.state = states.name) AS max_pop FROM states; then it is not possible to sort after max_pop or use max_pop in a function or a CASE. Here max_pop is naming the whole subselect. How ab

[GENERAL] General subselect question

2009-01-05 Thread Tim Hart
In the general case, is a subselect that uses union less performant than a union? I have a query that looks something like this: select from table1, table2, table3 where union select fromtable1, table2, table3 ref1, table3 ref2 wher