|
|
|
Re: selecting max five sal from a table [message #343779 is a reply to message #343757] |
Thu, 28 August 2008 02:18   |
 |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
@hamidmahmood,
Follow the guidelines:
- format your post
- don't give solution just clue
OraFAQ Forum Guide, "How to format your post?" section.
OraFAQ Forum Guide, "Responding to Posts" section:
Quote: | When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.
|
Regards
Michel
|
|
|
Re: selecting max five sal from a table [message #343799 is a reply to message #343566] |
Thu, 28 August 2008 03:39   |
swarit_gupta
Messages: 4 Registered: August 2008
|
Junior Member |
|
|
Hi,
best and simple way will be -
arrange the result from select command in desc order by using ORDER BY Clause.
then you can use cursor and fetch 5 rows with the help of while or FOR loop.
DECLARE
CURSOR dummy_cur
IS
SELECT int_field
FROM dummy_table order by int_field desc;
----int_field is the name of the column
dummy_row dummy_cur%ROWTYPE;
i number := 1;
BEGIN
OPEN dummy_cur;
WHILE i < 6
LOOP
FETCH dummy_cur INTO dummy_row;
DBMS_OUTPUT.put_line (dummy_row.int_field);
i := i + 1;
END LOOP;
CLOSE dummy_cur;
END;
--
Tried and tested
It might help you
Thanks
|
|
|
|
Re: selecting max five sal from a table [message #343837 is a reply to message #343566] |
Thu, 28 August 2008 05:54   |
aparangi_rhl
Messages: 10 Registered: January 2006
|
Junior Member |
|
|
Hi Ramakrishna,
You can also retrieve the MAX 5 salaries by using co-related queries. Try to write a query creating 2 aliases of the same table and use correlation. The hint is you should use count() function in the correlated sub query.
|
|
|
|
|
|
|
|
Re: selecting max five sal from a table [message #344519 is a reply to message #344518] |
Sat, 30 August 2008 03:17  |
 |
Michel Cadot
Messages: 68733 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Once again read OraFAQ Forum Guide.
1/ "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter).
Use the "Preview Message" button to verify.
2/ "Responding to Posts" section:
Quote: | When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.
|
In addition, your "solution" is wrong. The same and correct one has been given 2 days ago (with the same comments from me).
Regards
Michel
|
|
|