X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9D1BCD9045 for ; Fri, 4 Nov 2005 04:40:03 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53799-04 for ; Fri, 4 Nov 2005 08:39:58 +0000 (GMT) X-Greylist: delayed 00:24:21.432634 by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 11F94D8CAF for ; Fri, 4 Nov 2005 04:39:58 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id A104640C181; Fri, 4 Nov 2005 08:15:32 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 6ABA215EDA; Fri, 4 Nov 2005 08:13:03 +0000 (GMT) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22735-06; Fri, 4 Nov 2005 08:13:00 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1A0B915ED9; Fri, 4 Nov 2005 08:13:00 +0000 (GMT) Message-ID: <436B180B.8090908@archonet.com> Date: Fri, 04 Nov 2005 08:12:59 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Thomas Good Cc: Postgres SQL List Subject: Re: JOIN condition confusion References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.034 required=5 tests=[AWL=0.034] X-Spam-Score: 0.034 X-Spam-Level: X-Archive-Number: 200511/53 X-Sequence-Number: 23304 Thomas Good wrote: > Hi, > > I am wondering if there is a way to set conditions on a left joined > table without hosing the join altogether: > > query = qq |SELECT p.*, a.user_id > FROM patient_dosing p > LEFT JOIN patient_assignment a > ON p.patient_id = a.patient_id > WHERE p.dose_type = 'Missed (AWOL)' > AND (p.dose_date >= $start_date AND p.dose_date <= $end_date) > -- the next two conditions hose the left join > -- AND a.end_date IS NULL > -- AND lower(a.assign_type) = 'primary' > ORDER BY a.user_id, p.patient_id| if ($dbtype ne "oracle"); What do you want to happen? What do you mean by a left-join where the right-hand side has assign_type='primary'? -- Richard Huxton Archonet Ltd