Re: SQL Statement Help Needed

From: Marcus Engene <mengpg(at)engene(dot)se>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: SQL Statement Help Needed
Date: 2005-12-04 22:47:31
Message-ID: 43937203.8010800@engene.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

That would be the same trick as was shown to Srinivas Iyyer the other day:

select
m.membername
array (
select t.phonenumber
from membertelephone t
where t.member_id = m.id
)
from
member m

"Normally", I guess, people would filter.
Note that in this select you get a row for all members, if you do a join
you won't get a row for those members without a phone (unless you
specifically make it so, Oracle's (+) syntax, I don't know what that is
in pg?!)

Best regards,
Marcus

Michael Avila wrote:
> Thank you everyone.
>
> A received a few responses and they all work. However, with one member name
> but multiple telephone numbers, is there a way to not get the multiple
> member names, the same name with each telephone? Or do I have to "filter"
> that out myself?
>
> Thanks
>
> Mike
>
> -----Original Message-----
> From: Oliver Elphick
> Sent: Sunday, December 04, 2005 11:40 AM
> To: Michael Avila
> Subject: Re: [NOVICE] SQL Statement Help Needed
>
>
> On Sun, 2005-12-04 at 04:12 -0500, Michael Avila wrote:
>
>>... Is it possible to do a JOIN
>>with a table with one record with a table with multiple records?
>>
>>SELECT * FROM member
>>
>>SELECT * FROM membertelephone WHERE member_id = the id from the above
>
> SELECT
>
> The query would be:
>
> SELECT *
> FROM member AS m
> LEFT JOIN membertelephone as t
> ON m.id = t.member_id;
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Marcus Engene 2005-12-04 22:53:50 fts, compond words?
Previous Message Michael Avila 2005-12-04 22:08:28 Re: SQL Statement Help Needed