join table with empty fields and default

From: quickcur(at)yahoo(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: join table with empty fields and default
Date: 2006-07-22 19:47:42
Message-ID: 1153597662.359117.314080@i3g2000cwc.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2006-07-22 20:18:33 Re: join table with empty fields and default
Previous Message AL ELK 2006-07-22 18:09:05 Re: PGSQL 8.1.4 on Win2003 at istanbul :), could not access status of transaction xxxxx , could not open file "pg_subtrans/000A": Invalid argument