pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: multiple lookup per row
Date: Fri, 20 Jul 2001 10:39:16 +0100
Message-ID: <01072010391603.16118@gary.ringways.co.uk> (raw)

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     



view thread (4+ messages)  latest in thread

Message-ID: <01072010391603.16118@gary.ringways.co.uk>
Permalink:  ../01072010391603.16118@gary.ringways.co.uk/
Also on:    postgresql.org/message-id/01072010391603.16118@gary.ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: multiple lookup per row
  In-Reply-To: <01072010391603.16118@gary.ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox