Joins within a table

Поиск
Список
Период
Сортировка
От Steve Lefevre
Тема Joins within a table
Дата
Msg-id 466F255F.4020204@osu.edu
обсуждение исходный текст
Ответы 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>)
Список 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 по дате отправления:

Предыдущее
От: Steve Lefevre
Дата:
Сообщение: no results for nextval() query?
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: Joins within a table