pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hook <hook@kcp.com>
To: pgsql-sql@postgresql.org
Subject: max value from join
Date: Mon, 14 Jun 2004 11:02:06 -0500
Message-ID: <40CDCBFE.7070608@kcp.com> (raw)

I have a court program with related tables

 citation
  citkey   varchar(16) NOT NULL   PRIMARY KEY, 
    ....

 cdefendant   
  citkey   varchar(16) NOT NULL   PRIMARY KEY references citation, 
    ....

 ccourt
  citkey   varchar(16) NOT NULL   PRIMARY KEY references citation, 
    ....

 disposition
  citkey    varchar(16) NOT NULL  PRIMARY KEY references citation, 
    ....

 ccontinue
  citkey    varchar(16) NOT NULL references citation, 
    ....     

 warrant
  citkey    varchar(16) NOT NULL references citation,
    ....     


I am trying to extract data related to the last conttinue date using
 select 
    c.citkey, /* c.cdate, 
    c.badge,   c.vioDesc, 
    b.lname,   b.fname,    b.mi,      b.race,   b.dob,   b.sex,
    d.docket,  d.plea,     d.fine,    d.costs,  d.ddate, d.abdocket, d.bond,
    p.disDate, p.disDesc,  p.disCode, p.amount,
    */
    t.contDate,
    t.abcontinue,
    w.bndType, w.bndAmt 
    from citation c, cdefendant b, ccourt d, ccontinue t, 
         disposition p, warrant w 
    where c.citkey   = b.citkey  and 
          b.citkey   = d.citkey  and 
          d.citkey   = t.citkey  and 
          t.citkey   = p.citkey  and
          p.citkey   = w.citkey  
    group by 
          c.citkey, c.cdate, c.badge, c.vioDesc, 
          b.lname,  b.fname, b.mi, b.race, b.dob, b.sex,
          d.docket, d.plea,  d.fine,  d.costs, d.ddate, d.abdocket, d.bond,
          p.disDate, p.disDesc,  p.disCode, p.amount,
          t.abcontinue,  t.contDate,
          w.bndType, w.bndAmt
    having  max(t.contDate) = t.contDate
    order by c.citkey


I cannot seem to get unique rows with only the max contDate??

i.e.
   citkey   |  contdate   | abcontinue | bndtype | bndamt  
------------+-------------+------------+---------+---------
 991164031  | 06/07/2000  | 6          | Bond    |    0.00
 991164031  | 07/19/2000  | 6          | Bond    |    0.00



thanks





view thread (2+ messages)  latest in thread

Message-ID: <40CDCBFE.7070608@kcp.com>
Permalink:  ../40CDCBFE.7070608@kcp.com/
Also on:    postgresql.org/message-id/40CDCBFE.7070608@kcp.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: hook@kcp.com
  Subject: Re: max value from join
  In-Reply-To: <40CDCBFE.7070608@kcp.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