two fields in subselect
two fields in subselect
От:
Joseph Shraibman <jks@selectacast.net>
Дата:
I want to do this: SELECT a, (select x,y,z from table2 where table1.a = table2.w), b, c from table1; But postgres complains: ERROR: Subselect must have only one field How can I get around this?
Re: two fields in subselect
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Joseph Shraibman writes: > I want to do this: > SELECT a, (select x,y,z from table2 where table1.a = table2.w), b, c > from table1; > But postgres complains: > ERROR: Subselect must have only one field You haven't said what you expect to happen if table2 has zero or multiple matches to any one table1.a value --- but if you want a plain inner join you could do SELECT a, x, y, z, b, c from table1, table2 where table1.a = table2.w; regards, tom lane
Re: two fields in subselect
От:
Joseph Shraibman <jks@selectacast.net>
Дата:
Tom Lane wrote: > Joseph Shraibman writes: > > I want to do this: > > SELECT a, (select x,y,z from table2 where table1.a = table2.w), b, c > > from table1; > > But postgres complains: > > ERROR: Subselect must have only one field > > You haven't said what you expect to happen if table2 has zero or > multiple matches to any one table1.a value --- but if you want a > plain inner join you could do > > SELECT a, x, y, z, b, c from table1, table2 where table1.a = table2.w; > I can't do that. I guess I should have elaborated some more. What I really want to do is: SELECT a, (select x,y,z from table2 where table1.a = table2.w), b, (select x,y,z from table2 where table1.b = table2.w), c from table1; And table2.w is unique.