pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <richardh@archonet.com>
To: Jo <joacn@yahoo.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: How to write this query!
Date: Mon, 21 Jul 2003 12:46:02 +0100
Message-ID: <200307211246.02554.richardh@archonet.com> (raw)
In-Reply-To: <20030713163222.88233.qmail@web10305.mail.yahoo.com>
References: <20030713163222.88233.qmail@web10305.mail.yahoo.com>

On Sunday 13 July 2003 17:32, Jo wrote:
> These are my PostgreSQL tables:
>
> pid | name
>  1  |  A
>  2  |  B
>  3  |  C
>  4  |  D
>  5  |  E
>
> tid | pid 1 | pid 2 | pid 3
> 1   |  1    |  2    |  3
>
> Bascially, I would like to write a query to list only
> the names which their "pid" match those pids in the
> other table. If anyone knows, pls help!!

Jo - not sure how your message took this long to reach the list, but it 
doesn't look like someone has answered, so...

SELECT DISTINCT a.name FROM table_a AS a, table_b as b WHERE a.pid=b.pid1 OR 
a.pid=b.pid2 OR a.pid=b.pid3;

-- 
  Richard Huxton
  Archonet Ltd



view thread (2+ messages)

Message-ID: <200307211246.02554.richardh@archonet.com>
Permalink:  ../200307211246.02554.richardh@archonet.com/
Also on:    postgresql.org/message-id/200307211246.02554.richardh@archonet.com

 · 

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: richardh@archonet.com, joacn@yahoo.co.uk
  Subject: Re: How to write this query!
  In-Reply-To: <200307211246.02554.richardh@archonet.com>

* 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