Sam Stearns <sam.stearns@dat.com> writes:
> This one is really doing my head in:
> ...
> FROM (pud_fme_data d
> inner join csbuser u on (u.userid=d.user_id)
> inner join office o on (u.officeid=o.officeid)
> left outer join login l on (l.userid=u.userid) ) alias6;
> ERROR: invalid reference to FROM-clause entry for table "o"
> LINE 2: o.crmaccountid AS crm_account_id,
> ^
> DETAIL: There is an entry for table "o", but it cannot be referenced from
> this part of the query.
IIRC, the join alias "alias6" hides any table aliases inside it.
Leave that off. Or reference the column as "alias6.crmaccountid".
(This way might require fooling around with column aliases so that
crmaccountid is a unique column name within that scope.)
regards, tom lane