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_at_cpmsnbbsa02>
Date: Thu, 10 Jun 1999 19:04:13 -0500
Message-ID: <usAxc45s#GA.152_at_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 Fri Jun 11 1999 - 02:04:13 CEST