|
-
Actually, jmodic was on the right track, as the analytical functions are your best bet, but before I get to the solution...
There were many excellent answers here. The problem you are going to have is implementing them, since your original statement sounds rather complicated. Given this complication, however, one must also consider performance. (Personally, I think one should *always* consider performance, but that's just me :) ). With that in mind, restricting the result set at the earliest possible time would be best. Therefore, the suggestion of finding the disting values first, and restricting that set might be best. However, this can get extremely complicated if you do not know your ultimate result set. I mean, just because I pick 3 states that I know are in table B does not mean that those 3 states will appear in the final result set. Therefore, you would have to apply all the restrictive criteria just to get the distinct set of usable states, then re-join and re-restrict everything again to get the full results. So, while the performance-dictator in me screams that we should do everything humanly possible to restrict the result set as early as possible, I must admit that this may not be a case where that can be done. Mind you, I don't have all the details, so it *may* be possible and *should* be explored.
However, having said all that, what you appear to need is almost what jmodic gave you, just a different analytical function:
SELECT
---COLA,
---COLB
FROM
(
---SELECT
------DENSE_RANK() OVER (ORDER BY T1.COLA)
---------AS MYRANK,
------T1.COLA,
------T2.COLB
---FROM
------T1,
------T2
---WHERE
------...
---)
WHERE
---MYRANK <= 3
Hope this helps,
- Chris
BTW - call me slow, but am I the last one to know that Oracle now supports the CASE construct?? I would have thought that one would have been on the front page of the POST! :) I am beside myself with joy - I'm never going to have to write a DECODE again!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|