Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: self join help for an Oracle newbie

Re: self join help for an Oracle newbie

From: Brian Peasland <peasland_at_email.msn.com>
Date: Thu, 10 Jun 1999 19:04:13 -0500
Message-ID: <usAxc45s#GA.152@cpmsnbbsa02>

>I guess I could use VB to Loop through the two
>tables but this may take forever...is there a way to do a self join on
Table
>B that grabs only the record with the lowest date for a singel CustomerID
>and then join this resultset
>to Table As?

Try this!

  Assume TableB has two columns, CustomerID and tDate (for transaction date).
  TableA has a column called CustomerID

SELECT a.CustomerID, b.tDate
FROM TableA a,
(SELECT b.CustomerID,MIN(b.tDate) FROM TableB b GROUP BY b.CustomerID) WHERE a.CustomerID=b.CustomerID;

I think this might work, but I don't have access right now to test it out.

Hope that helps,
Brian Peasland
peasland_at_msn.com Received on Thu Jun 10 1999 - 19:04:13 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US