Microsoft
Software
Hardware
Network
Question : Select top N and their types
I'm having a bugger of a time writing this SQL query (Oracle 10g)....
I have two tables. For every unique transaction ID in TABLE1, there can be many transaction types associated with it in TABLE2. What I want to do is retrieve the 5 most recent (biggest) transaction IDs in TABLE1 for a given user and all transaction types from TABLE2 associated with those 5 ids. For example if the 5 biggest transaction ids in table TABLE1 are 6-10, and in TABLE2 types "apples" and "oranges" can exist, the output might look like:
Transaction ID / Type
---------------------
6 / apples
7 / apples
8 / apples
8 / oranges
9 / apples
10 / apples
In the example, I have 6 rows returned, but they're still only based on the 5 most recent (biggest) ids.
This is what I have so far. The query is supposed to grab all the types and ids based on the 5 most recent ids.
SELECT t1.unique_id, t2.type_id
FROM TABLE1 t1, TABLE2 t2
WHERE t1.unique_id = t2.unique_id
AND t2.unique_id in (
SELECT t1.unique_id
FROM TABLE1 t1
WHERE t1.user_id = 'myUser'
AND ROWNUM <= 5
)
Any help is appreciated.
Answer : Select top N and their types
I bought a trip lite rack mount UPS. It was mostly DOA on arrival. They sent me another one and now its charging. I have heard locally cyber power is good so I will start using them more.
Random Solutions
Custom control communicating an event to parent form
Exchnage database restoration
MailMerge: filter results from Access
Citrix presentation Svr 4.5 - Data collector election
Need small help
Temporary URL in Plesk
Get World Cup ticket in reasonable price
ASP.Net C#, MS SQL
Passing a structure from VBA in Excel to a C DLL
Javascript form validation problems