Re: Joins within a table - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: Joins within a table
Date
Msg-id 19423.32520.qm@web31810.mail.mud.yahoo.com
Whole thread Raw
In response to Joins within a table  (Steve Lefevre <lefevre.10@osu.edu>)
List pgsql-novice
--- Steve Lefevre <lefevre.10@osu.edu> wrote:

> Hello all -
>
> I'm trying to do a JOIN within a table. In MySQL, I would do
>
> SELECT  main_table.field, join_table.field
> FROM main_table
> LEFT JOIN main_table AS join_table ON join_table.id = main_table.parent_id

PostgreSQL conforms to the SQL standard when it comes to giving alias names to a single table and
doesn't use MySQL's vendor specific extension:

         SELECT Instance1.field, Instance2.field
           FROM Main_table AS Instance1
LEFT OUTER JOIN Main_table AS Instance2
             ON Instance1.id = Instance2.id;

Here I am showing two alias names, but you could reduce this query to use only one if you wanted.

Regards,
Richard Broersma Jr.

pgsql-novice by date:

Previous
From: Steve Lefevre
Date:
Subject: Joins within a table
Next
From: "Andrew Maclean"
Date:
Subject: Re: Joins within a table