Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id F114363161C for ; Sun, 21 Feb 2010 19:25:36 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 90166-04 for ; Sun, 21 Feb 2010 23:25:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.25]) by mail.postgresql.org (Postfix) with ESMTP id 812F1632704 for ; Sun, 21 Feb 2010 19:25:26 -0400 (AST) Received: by qw-out-2122.google.com with SMTP id 3so374361qwe.61 for ; Sun, 21 Feb 2010 15:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=prxBcSySgw3juD3x6B4bK0LnGrg/JxrVST/VtFxqQ0Q=; b=x3GCbwe7GHNyjFDp/8pjhI7G/H8YP8KDU1XJrc/lWpVhXe6CKRC0xogymHc0z7KgZW 4c9uqm0xLk63VKcFSWllXRUh6ahE2ebEmiDNwAyLe/8VuS4ighi0Tcf+5fILkv/0tGoC te3oTnAUNVnHtq4eodtsxD9JroNwdRxe4FE04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=svyMIaSOX0w4yYvJNAGxFxo2SruOODF5ClrOXoKj88OHlEq/aD3JBNLjectORwEN17 kn0MivFEpfQLlx1x8NfF65cd2lPrW8KxDUSD/a9QARMMX3Ea2Z8zxDwPpesNMxLxX+KC yoJp048AMASU2Oct8hx5yMqgjr5qE163DtHr0= MIME-Version: 1.0 Received: by 10.229.55.69 with SMTP id t5mr2614719qcg.34.1266794724927; Sun, 21 Feb 2010 15:25:24 -0800 (PST) Date: Sun, 21 Feb 2010 18:25:24 -0500 Message-ID: <302670f21002211525r65caee9et396c374a3cd64b0d@mail.gmail.com> Subject: Join Advice and Assistance From: Gary Chambers To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/83 X-Sequence-Number: 33682 All, I've encountered a mental block due primarily to my inexperience with moderately complex joins. Given the following three tables: Table "public.users" Column | Type | Modifiers -----------+------------------------+----------------------- userid | bigint | not null lname | character varying(64) | not null fname | character varying(64) | not null passwd | character varying(64) | not null is_active | boolean | not null default true Table "public.user_emailaddrs" Column | Type | Modifiers -----------+------------------------+----------------------- userid | bigint | not null emailaddr | character varying(256) | not null is_active | boolean | not null default true Table "public.usermetas" Column | Type | Modifiers ----------------+-----------------------------+------------------------ userid | bigint | not null startdate | timestamp without time zone | not null default now() lastlogindate | timestamp without time zone | not null default now() lastpwchange | timestamp without time zone | not null default now() logincount | integer | not null default 1 users and usermetas is a one-to-one relationship. users and user_emailaddrs is a one-to-many relationship. What is the best way to get these tables joined on userid and return all emailaddr records from user_emailaddrs (e.g. if userid has three (3) e-mail addresses in user_emailaddrs)? Is there any way to avoid returning all fields in triplicate? Please feel free to criticize where necessary. Thank you very much in advance. -- Gary Chambers /* Nothing fancy and nothing Microsoft! */