Beginner question - select with multiple tables

From: Dave Inskeep <dinskeep(at)yahoo(dot)com>
To: Postgres SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Beginner question - select with multiple tables
Date: 1999-01-20 04:51:27
Message-ID: 19990120045127.28717.rocketmail@send103.yahoomail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I'm trying to perform a select over several tables I've created. There
are five tables - the first contains message header information and a
key field (called node). The other four contain message body
information and the same node field. I'm getting unexpected results
when I query across the multiple tables.

The following statement does not work if there are not any records in
vall_bod2:

select distinct vall.node from vall, vall_bod1, vall_bod2 where
( vall.node = vall_bod1.node and vall_bod1.bod1 LIKE '%brake%' ) or
( vall.node = vall_bod2.node and vall_bod2.bod2 LIKE '%brake%' );

However, if I insert a record into vall_bod2 (whether or not it
contains the word brake) and a corresponding header record into vall
with a matching node, the same exact query will return the nodes of
all records in vall_bod1 with the word 'brake' in the bod1 field.

The same holds true if I query across vall_bod1, 2, and 3, and there
are no records in vall_bod3. If I insert a single record in vall_bod3,
even if it doesn't match, the query will work for matching records in
vall_bod1 and vall_bod2. Ditto when I try across 1-4.

Can someone explain why this happens, am I doing something wrong? Is
there a better way to achieve the same results, i.e. JOINS? Does
Postgresql support JOINS?

Many thanks,
Dave Inskeep

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-01-20 09:44:01 Re: [SQL] Beginner question - select with multiple tables
Previous Message Brian Baquiran 1999-01-19 23:58:30 Re: [SQL] set type and in clause