join table with empty fields and default

Поиск
Список
Период
Сортировка
От quickcur@yahoo.com
Тема join table with empty fields and default
Дата
Msg-id 1153597662.359117.314080@i3g2000cwc.googlegroups.com
обсуждение исходный текст
Ответы Re: join table with empty fields and default
Список pgsql-general
Hi, suppose I have two tables

table User
{
    id integer,
    name text,
    address text
}

Table UserWork
{
    userid integer references User(id),
    work text
}

Suppose I have three users

id    name    address
1     Tony      main street
2     Peter     Big ave
3     Richard  Loop Blvd

And two of them work

UserWork
userid        work
1               programming
3               studying

I would like to join table user and userwork, where if a user has a
work, I list it. If he does not, I give it some default value "no work"

Join User and UserWork
id    name    address              work
1     Tony      main street        programming
2     Peter     Big ave              no work
3     Richard  Loop Blvd          studying

How can I write the sql?

Thanks,

qq


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

Предыдущее
От: "Jasbinder Bali"
Дата:
Сообщение: ECPG. Badly stuck
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: join table with empty fields and default