Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: self join help for an Oracle newbie
>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
![]() |
![]() |