Re: Syntax question

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: John Taylor <d_low22003(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Syntax question
Date: 2006-05-26 16:35:42
Message-ID: 20060526163542.GA13481@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, May 26, 2006 at 09:09:25 -0700,
John Taylor <d_low22003(at)yahoo(dot)com> wrote:
> I have a select statement that goes as follows:
>
> SELECT * FROM product prod, prod_alias pa, category cat, company co
> WHERE prod.catid = cat.catid
> AND prod.coid = co.coid
> AND prod.prodid = pa.prodid;
>
> If possible, I want to change the statement so that I get output regardless of whether there's a match between prod.prodid and pa.prodid. IOW, if there's a match between prod.prodid and pa.prodid, I want the output from both the product table and the prod_alias table. if there's no match, I still want the output from product table. Can I do this in one select statement?

This is what outer joins are used for. See
http://developer.postgresql.org/docs/postgres/sql-select.html
for the syntax and a very brief description of what they do.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2006-05-26 16:41:26 Re: Syntax question
Previous Message Jorge Godoy 2006-05-26 16:16:35 Re: LDAP authentication