Re: SQL Dummy Needs Help

From: Andrew Perrin <aperrin(at)socrates(dot)berkeley(dot)edu>
To: Alder <Terrence(dot)Branscombe(at)gems8(dot)gov(dot)bc(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL Dummy Needs Help
Date: 2001-03-13 01:34:49
Message-ID: Pine.LNX.4.21.0103122031510.11255-100000@nujoma.perrins
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Well, you should probably get yourself a good SQL book :) but here's a try
(untested). How about something like:

SELECT DISTINCT title_no, paidto_date
FROM table1, table2
WHERE table1.title_no = table2.title_no
AND table1.effect_date <> table2.paidto_date;

Again, untested - try it and see.

----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology
(Soon: Asst Professor of Sociology, U of North Carolina, Chapel Hill)
andrew_perrin(at)unc(dot)edu - http://www.unc.edu/~aperrin

On Fri, 9 Mar 2001, Alder wrote:

> I'm pretty new to SQL and can't figure out how to write what should be a
> simple query of two tables. Could someone here possibly help me out?
>
> Table 1 has two fields I'm interested in: TITLE_NO and EFFECT_DATE
> Table 2 also has two fields of interest: TITLE_NO and PAIDTO_DATE
>
> TITLE_NO is unique in Table 1, meaning each TITLE will have a unique
> EFFECT_DATE. Table 2 represents an accounting history of each TITLE, so for
> each TITLE_NO there may be one or more PAIDTO_DATE values. In both Tables
> the _DATE fields are stored as 9-character strings in the fomat YYYYMMDD.
> In all cases, the MM and DD values in Table 2 should be identical with those
> in Table 1.
>
> My intention is to produce a list that will contain the TITLE_NO of each
> TITLE where the MMDD value for EFFECT_DATE differ from any of the
> PAIDTO_DATE values for that TITLE_NO. The list must contain ONLY the
> PAIDTO_DATE values that differ, and the corresponding TITLE_NO.
>
> Sorry I can't explain this a little more technically, but if anyone can
> advise me, that would be fabulous.
>
> Thanks,
> Terry
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Cliff Crawford 2001-03-13 02:14:21 Re: SQL Dummy Needs Help
Previous Message Spy 2001-03-13 01:31:06 Re: Use of the LIMIT clause ?