pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Roberto Mello <rmello@cc.usu.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Getting matching and non-matching results (long)
Date: Wed, 5 Dec 2001 13:07:20 -0800 (PST)
Message-ID: <20011205130527.W17641-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <20011205123703.A2725@cc.usu.edu>

> create table sds_grades (
> 	grade_id integer
> 		constraint sds_grades_pk primary key,
> 	grade_name varchar(100)
> );
>
> create table sds_offenders (
> 	offender_id integer
> 		constraint sds_offenders_pk primary key,
> 	participant_id integer
> 		constraint sds_offenders_part_id_fk references sds_participants,
> 	incident_id integer
> 		constraint sds_offenders_incident_id_fk references sds_incidents on delete cascade,
> 	unknown_count integer,
> 	grade_id integer
> 		constraint sds_offenders_grade_id_fk references sds_grades,
> ...
> );
>
> SELECT COUNT(incident_id), drug_name, grade_name
> FROM sds_offenders o, sds_drugs d, sds_drug_offenses do, sds_grades g
> WHERE o.drug_p = 't'
>   AND o.offender_id = do.offender_id
>   AND d.drug_id = do.drug_id
> GROUP BY drug_name, grade_name, d.sort_key
> ORDER BY d.sort_key

I think you need a
g.gradeid=o.gradeid
in the where clause as well to constrain g to
the grade for which the offender belonged, right?




view thread (4+ messages)  latest in thread

Message-ID: <20011205130527.W17641-100000@megazone23.bigpanda.com>
Permalink:  ../20011205130527.W17641-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20011205130527.W17641-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, rmello@cc.usu.edu
  Subject: Re: Getting matching and non-matching results (long)
  In-Reply-To: <20011205130527.W17641-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox