On Thursday 04 March 2004 11:20, Philippe Lang wrote: [working query] > It works fine.
Excellent! :-) Oh - there's more :-( > Now, I need to do something else: the parameter of my sub-select is also > a member of the table I'm selecting. > > SELECT > > tableA.field1, > tableA.field2, > > tableB.field1, > tableB.field2, > > ( > SELECT tableB.field2 > FROM tableB > WHERE tableB.field1 = tableB.field1 (--> from-main-select?) - 1; > ) AS p > > FROM tableA > INNER JOIN tableB > ON tableA.pk = tableB.FK; > ------------------------------------------- > > How can I refer to the tableB.field1 parameter from the main query? I've > tried to do something like this, but without success: You're along the right lines, except I think you want to alias the table not the column. ... ( SELECT x.field2 FROM tableB AS x WHERE x.field1 = tableB.field1 - 1 ) ... HTH -- Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html