Unix Technical Forum

Re: SQL Statement Help Needed

This is a discussion on Re: SQL Statement Help Needed within the pgsql Novice forums, part of the PostgreSQL category; --> Thank you everyone. A received a few responses and they all work. However, with one member name but multiple ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:20 PM
Michael Avila
 
Posts: n/a
Default Re: SQL Statement Help Needed

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 [mailtolly@lfix.co.uk]
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;

--
Oliver Elphick olly@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:20 PM
Marcus Engene
 
Posts: n/a
Default Re: SQL Statement Help Needed

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;
>


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:01 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com