Joins within a table - Mailing list pgsql-novice

From Steve Lefevre
Subject Joins within a table
Date
Msg-id 466F255F.4020204@osu.edu
Whole thread Raw
Responses Re: Joins within a table  (Richard Broersma Jr <rabroersma@yahoo.com>)
Re: Joins within a table  ("Andrew Maclean" <andrew.amaclean@gmail.com>)
Re: Joins within a table  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
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

Or something like that.

However, in the Postgres documentation, I don't see anything on JOIN AS.
How would I do a join within a table in Postgres?

The table in question is a genetics table of viruses. The columns are
id, strain, and parent_id. Since viruses only replicate, each strain has
one parent. This way I can have one table and show entire tree of the
relationship. It guarantees that I have only one parent per virus.

The only other way I can think of doing it would be to have two tables:

table strains
------------
id
strain

table relationships
--------------
parent_id
child_id


But then I think I would have to implement some constraints so that I
don't get more than one parent per child.

pgsql-novice by date:

Previous
From: Steve Lefevre
Date:
Subject: no results for nextval() query?
Next
From: Richard Broersma Jr
Date:
Subject: Re: Joins within a table