|
-
Top 5 Priority Rows In order by?
Hi,
I have a requirement to print top 5 rows in a sequence based on the Priority_key. let's see we have table test_table with 2 columns below
Priority_key Code
1 A2
2 AA
4 A3
9 A1
6 A8
3 AZ
8 AX
The Output I want
1. Order by Priority_key
2. Only first 5 priority rows
Output
Priority_key Code
1 A2
2 AA
3 AZ
4 A3
6 A8
Please help to resolve this, thanks in advance.
-
Hi
Try
select priority_key,code
from (select priority_key,code ,rownum rn
from table
order by priority_key) X
where x.rn<6;
regards
Hrishy
-
Hi hrishy,
Thanks for the help but its not working according to my requirement.
Please consider the below values
Priority_key Code
1 A2
2 AA
4 A3
9 A1
6 A8
3 AZ
8 AX
and need the output as a
1 A2
2 AA
3 AZ
4 A3
6 A8
Thanks
Last edited by aph; 08-28-2004 at 10:28 PM.
-
If you would have taken a minute of your time and actualy run the query hrishy has suggested, you'd have found out that it is returning exactly the output that you want.....
Jurij Modic
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
-
I am sorry hrishy & jmodic, yes I was wrong it is working thanks. Now I need another help. What if I have a another table test_table2 and columns code & description and want to join with my test_table code with test_table2 code to get description.
TEST_TABLE
----------
Priority_key Code
1 A2
2 AA
4 A3
9 A1
6 A8
3 AZ
8 AX
TEST_TABLE2
-----------
Code Description
A2 Computer
AA Mouse
A3 Hard Disk
A1 keybord
A8 Memory
AZ Network Card
AX USB Port
Now based on the first table TEST_TABLE join column Code with TEST_TABLE2 column Code and print description but the same requirement 'Top 5 priority rows in order by'.
Thanks
-
Try this query
SELECT A.priority_key, A.code, B.DESCRIPTION
FROM (select priority_key,code from (select priority_key,code ,rownum rn from T1
order by priority_key) X where x.rn<6) A,
T2 B
WHERE B.CODE = A.CODE
ORDER BY A.priority_key
-
Thanks it works perfect!!!
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
|