JOIN condition confusion

From: Thomas Good <tomg(at)sqlclinic(dot)net>
To: Postgres SQL List <pgsql-sql(at)postgreSQL(dot)org>
Subject: JOIN condition confusion
Date: 2005-10-31 18:28:01
Message-ID: Pine.LNX.4.44.0510311325420.17323-100000@q8.nrnet.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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");

Thanks much!
Tom

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Axel Rau 2005-10-31 18:53:57 Poor performance in inet << cidr join
Previous Message Alessandro Busato 2005-10-31 17:43:19 pgSQL, executing generic query