Re: left outer join on multi tables

Поиск
Список
Период
Сортировка
От Richard Broersma Jr
Тема Re: left outer join on multi tables
Дата
Msg-id 20061011053147.12269.qmail@web31802.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на left outer join on multi tables  (quickcur@yahoo.com)
Ответы query log corrupted-looking entries  ("George Pavlov" <gpavlov@mynewplace.com>)
Re: left outer join on multi tables  (Richard Broersma Jr <rabroersma@yahoo.com>)
Re: left outer join on multi tables  ("Ge Cong" <gecong@gmail.com>)
Список pgsql-general
> 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.

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Broersma Jr
Дата:
Сообщение: Re: restoring a file system backed-up data dir
Следующее
От: "George Pavlov"
Дата:
Сообщение: query log corrupted-looking entries