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
HELP! Windows SBS 2008 server keeps hanging URGENT!
To change asni_padding setting of a column.
Sharepoint Webpart page load event issue
Impersonate a logged on user
Cisco Unity Express to Trigger MWI on overlay DN
Reverse DNS does not match SMTP Banner
Javascript to get <TD> inner text in MSIE, FF and Chrome
Pass recordset from local sql server to remote sql server using access adp
Intermittent internet connectivity for PCs in small remote office
Strip out ’s in mySQL query | XML Parsing Error: undefined entity