Re: How Two JOINS from one table - Mailing list pgsql-general

From sql@hayes.ch (Simon Hayes)
Subject Re: How Two JOINS from one table
Date
Msg-id 60cd0137.0408090518.1aa94881@posting.google.com
Whole thread Raw
In response to How Two JOINS from one table  (ree <ree@hotmail.coom>)
List pgsql-general
ree <ree@hotmail.coom> wrote in message news:<Xns9540C069A4F5Areehotmailcoom@211.29.133.50>...
> I got this problem where I need to look up values in two columns from
> another table.
>
> I can get OUTER LEFT JOIN working when looking up one column from a table
> but when looking up at two columns from a table I can't get the SQL syntax
> correct.
>
> The scenario is
>  A table has definitions for abbreviation of initials. From my search query
> there are two columns of initials, I am having problems in writing an SQL
> statement to look up and replace both columns of initials with their
> correct definitions. I was using an OUTER LEFT JOIN statement
>
>
> I am sorry if this isnt the correct Newsgroup to post this.

Without DDL, sample data and expected results this is a complete guess
(using MSSQL syntax):

update
    dbo.MyTable
set
    col1 = isnull(a.Definition,col1),
    col2 = isnull(b.Definition,col2)
from
    dbo.MyTable t
    left outer join dbo.Abbreviations a
    on t.col1 = a.Abbreviation
    left outer join dbo.Abbreviations b
    on t.col2 = b.Abbreviation

Simon

pgsql-general by date:

Previous
From: "Dan Ruthers"
Date:
Subject: BIGINT indexes still with problems
Next
From: "Brigitte ROLLAND"
Date:
Subject: Problems with MS Visual Basic 6.0