pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Colin Dick <cdick@mail.ocis.net>
To: pgsql-sql@postgreSQL.org
Subject: More on... Multiple table selection. (fwd)
Date: Wed, 5 Aug 1998 09:24:00 -0700 (PDT)
Message-ID: <Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net> (raw)

Hi, I posted this before but messed up what I was trying to do.  In the
below example, I would like to select all information from multiple tables
based on search information from either or both table.  The search
information may or may not include the idnum...

ex: select a.firstname, b.phone from a, b where a.firstname ~* 'bob'; 

OR LIKE

select a.firstname, b.phone from a, b where a.firstname ~* 'bob' and
b.phone ~ '567';

Basically, I think I need to do a join using the key field of idnum but
have never done that before.  Can someone draw a quick statement up for
me.  Can this be done in one statement.  I can do it in two or three 
easily but then where is the power of the database.... Thanks again.

--
Colin Dick
On Call Internet Services
cdick@mail.ocis.net


--================Original Post======================--

	I am new to the more complex SQL statements and I am having
trouble creating the statement I need.

	I have two tables:

table a			table b
-------                 -------
idnum (unique)		idnum (unique)
firstname		phone
lastname		fax


I want to be able to search the table for any value (sometimes multiple
values) and bring back all the information for all tables with the same
idnum. Would a query similar to the following do it. 

select a.idnum, a.firstname, a.lastname, b.phone from a, b where
a.firstname='bob' and b.fax='123-4567' and (a.idnum=b.idnum);

Does that statement make sense?  Or can someone make a suggestion to help
me acclomplish the task.  Thadvanceanks...

--
Colin Dick
On Call Internet Services
cdick@mail.ocis.net




Message-ID: <Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net>
Permalink:  ../Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net/
Also on:    postgresql.org/message-id/Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: cdick@mail.ocis.net
  Subject: Re: More on... Multiple table selection. (fwd)
  In-Reply-To: <Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net>
  References: <Pine.LNX.3.96.980805092328.21041B-100000@ocis.ocis.net>

* 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