This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL query for top ten students

 
faisal khan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have table name Student(name,marks,....)
I want to write the query that fetch the TOP TEN Students from the Student Table on the basis of their marks
regards
Faisal
[ March 18, 2004: Message edited by: Bear Bibeault ]
 
David Peterson
author
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a SELECT statement with an ORDER BY clause and then pull off just the first ten rows using a for loop. Alternatively some databases allow you to specify the number of rows to return, as part of the query (e.g. the syntax in SQL Server is SELECT TOP 10 .... In MySQL it comes as the end of the query as ... LIMIT 10). Check out the documentation for your database.
 
faisal khan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply
but i want sql query for this in oracle
please send me the code
regards
Faisal :roll:
 
Tom Blough
Ranch Hand
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Oracle, try:

Tom Blough
 
faisal khan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for sending query but it do not give the results that i want..
please send me the correct query for getting Top 10 students according
their (marks)
Faisal
 
Amy Phillips
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Faisal,
In oracle you can use Rank and then specify how many of the records to return so in this case 10. Have a search in google and you will find some good examples of how to use it.
Amy
 
shankar vembu
Ranch Hand
Posts: 309
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Peterson:
You could use a SELECT statement with an ORDER BY clause and then pull off just the first ten rows using a for loop.

I would prefer to do this, other alternatives are database dependent.
Regards.
 
faisal khan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks .....
 
Raj Ma
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you try this..
SELECT * FROM
(SELECT STUDENT.*, DENSE_RANK() OVER(ORDER BY MARKS DESC) AS RK
FROM STUDENT)
WHERE RK <=5
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic