selecting information from two tables (problem)

From: swatts(at)computer-systems(dot)com (Shaun)
To: pgsql-general(at)postgresql(dot)org
Subject: selecting information from two tables (problem)
Date: 2003-10-29 15:53:34
Message-ID: f3c408af.0310290753.5b899e77@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What I am trying to do is select all the rows out of the categories
table (see below) and select the sum of j_amount out of the judgment
table. Right now it is only returning the categories that are in the
judgment table. I want it to return those fields with the amounts out
of the judgment table, but also the all the other categories from the
categories table with 0 as there amount. Does anyone have a
suggestion.

select ca_code,ca_desc,sum(j_amount) as sum_amt,ca_dis_cycle
from categories LEFT OUTER JOIN judgment ON
(j_category=ca_code)
where j_case_no='45698'
and j_party_no=1
group by ca_code,ca_desc,ca_dis_cycle

thanks,
sw

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Johnston 2003-10-29 15:58:56 N Texas PostgreSQL Consultant Needed
Previous Message Edwin Quijada 2003-10-29 15:53:13 Error size varchar