Re: left outer join on multi tables

From: "Ge Cong" <gecong(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: left outer join on multi tables
Date: 2006-10-11 13:59:23
Message-ID: 1160575163.533817.291260@b28g2000cwb.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Thank you, But there seems to be syntax errors. Could you help?

Richard Broersma Jr wrote:
> > table name
> > {
> > id integer primary key
> > first_name text,
> > middle_name text,
> > last_name text
> > }
> >
> > table address
> > {
> > id integer primary key
> > number int,
> > street text,
> > city text,
> > state text
> > }
> >
> > table work
> > {
> > id integer primary key
> > hours text,
> > shift
> > }
> >
> > table person
> > {
> > id integer primary key
> > namid integer references name(id),
> > addressid integer referenes address(id),
> > workid integer references work(id)
> > }
> > nameid, addressid or workid in person table may be empty.
> > I would like to make a view which shows all information about a person
> > in one row
> > first_name, last_name, street, city, workhours, ...
> > In the peron table, if the workid, addressid, or nameid is empty, just
> > do not display the correspodent information.
> > I think I need left outer join, but I do not know how to use it. Could
> > anyone help?
>
> CREATE VIEW AS
> SELECT N.first_name,
> N.last_name,
> A.street,
> A.city,
> W.hour,
> ....
> FROM person P
> LEFT JOIN ON (P.namid = N.id)
> LEFT JOIN ON (P.addressid = A.id)
> LEFT JOIN ON (P.workid = W.id)
> ;
>
> Hopefully this is all correct and is what you are looking for?
>
> Regards,
>
> Richard Broersma Jr.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2006-10-11 14:03:49 Re: How does PG access wal files?
Previous Message Brad Nicholson 2006-10-11 13:47:55 How does PG access wal files?

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2006-10-11 14:04:10 Re: hstore isexists
Previous Message Teodor Sigaev 2006-10-11 13:43:11 Re: hstore isexists