From: | quickcur(at)yahoo(dot)com |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: join table with empty fields and default |
Date: | 2006-07-22 20:38:38 |
Message-ID: | 1153600718.477543.274120@p79g2000cwp.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thank you for your post. To make things a little bit complicated:
Suppose I have another table UserInformation
UserInfomation
{
userid integer referenes user(id),
mothername text
}
I would like methername also appear in the final join. Suppose each
user must have a mothername.
Could you please whow me the sql again?
Thanks again,
Michael Fuhr wrote:
> On Sat, Jul 22, 2006 at 12:47:42PM -0700, quickcur(at)yahoo(dot)com wrote:
> > 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"
>
> You could use an outer join and COALESCE.
>
> http://www.postgresql.org/docs/8.1/interactive/tutorial-join.html
> http://www.postgresql.org/docs/8.1/interactive/queries-table-expressions.html#QUERIES-JOIN
> http://www.postgresql.org/docs/8.1/interactive/functions-conditional.html#AEN12639
>
> Example:
>
> SELECT u.id, u.name, u.address, COALESCE(uw.work, 'no work') AS work
> FROM "user" AS u
> LEFT OUTER JOIN userwork AS uw ON uw.userid = u.id;
>
> --
> Michael Fuhr
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2006-07-23 01:04:24 | 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 |
Previous Message | Michael Fuhr | 2006-07-22 20:18:33 | Re: join table with empty fields and default |