| From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> | 
|---|---|
| To: | Steve Lefevre <lefevre(dot)10(at)osu(dot)edu>, pgsql-novice(at)postgresql(dot)org | 
| Subject: | Re: Joins within a table | 
| Date: | 2007-06-12 23:23:42 | 
| Message-ID: | 19423.32520.qm@web31810.mail.mud.yahoo.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-novice | 
--- Steve Lefevre <lefevre(dot)10(at)osu(dot)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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Maclean | 2007-06-12 23:32:32 | Re: Joins within a table | 
| Previous Message | Steve Lefevre | 2007-06-12 22:59:43 | Joins within a table |