Josh Berkus wrote:
> Joseph,
> 
> 
>>How do you do a subselect in the from clause?
>>
> 
> Assuming that you are using 7.1.0 or higher:
> 
> SELECT tbla.a, tbla.b, total_b 
> FROM tbla, 
>    (SELECT b, sum(f) as total_b FROM tblb GROUP BY b) b_tot
> WHERE tbla.b = b_tot.b
> 

OK my query was like:
select u.field1, ... , d.field1, ... (select ml.field from ml WHERE ml.key = u.key 
order 
by ml.keyfield desc limit 1) as lastml FROM utable u, dtable d, WHERE u.key = d.key 
and 
... and (sublectect again) = 2;

OK when I tried to convert the query:
select u.field1, ... , d.field1, ..., mll.lastml FROM utable u, dtable d,(select 
ml.field 
as lastml from ml WHERE ml.key = u.key order by ml.keyfield desc limit 1) mll WHERE 
u.key 
= d.key and ... and lastml = 2;

I got:
ERROR:  Relation 'u' does not exist


The key fields in the subselect must match up with the key fields in the outside 
query. 
I'm afraid this would indicate that they would not match up (even if I didn't use 
short 
aliases for the tables) and the result of the subselect would be meaningless.




-- 
Joseph Shraibman
[EMAIL PROTECTED]
Increase signal to noise ratio.  http://www.targabot.com


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to