multiple lookup per row

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: "pgsql-sql" <pgsql-sql(at)postgresql(dot)org>
Subject: multiple lookup per row
Date: 2001-07-20 09:39:16
Message-ID: 01072010391603.16118@gary.ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all,

I've got a table 'phones' which has an indexed key 'pid' of type int4, and a
phone number of type varchar(12).

I've then got a table 'members' which as an index key 'mid' of type int4.

Now, obviously, if each member only had one phone number, I could simply pull
it in using a join. My problem is that each member has (potentially) a voice
line 'mphone', a fax line 'mfax', and a mobile (that's a cellphone to you lot
over the pond) 'mmobile'.

How would I embelish a 'select * from members........' so that it included
the three phone numbers if they exist?

The only solution I can think of is to write a plpgsql function to do the
lookup and call that three times as part of the select, something like

select *, getphone(mphone) as phone, getphone(mfax) as fax.....

but a purely SQL solution would be nicer.

--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mattis Jiderhamn 2001-07-20 09:44:08 Cast '' (blank) to null date
Previous Message David M. Richter 2001-07-20 08:49:34 Query optimizing - paradox behave