Re: sub-select parameter problem
От | Richard Huxton |
---|---|
Тема | Re: sub-select parameter problem |
Дата | |
Msg-id | 200403041151.21946.dev@archonet.com обсуждение исходный текст |
Ответ на | sub-select parameter problem ("Philippe Lang" <philippe.lang@attiksystem.ch>) |
Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: