View previous topic :: View next topic |
Author |
Message |
Rama_Prayaga Beginner

Joined: 20 May 2003 Posts: 45 Topics: 15
|
Posted: Mon Jan 09, 2006 2:36 pm Post subject: select WITH ORDER BY expresion |
|
|
Hi ,
Following is a Similar Qurey which I am writing in a PL/1 application program.
Code: | Select ID, Name, Place
from Table_name
Order by Name
Fetch first 2000 rows only; |
The above query is consuming lot of time as the table has huge data,Since I am using ORDER BY clause.
Is there any way I could write a SQL query FETCH first 2000 rows then ORDER by Name.
All I need to fetch 2000 rows and then sort by Name thru SQL..
Kindly , help me in this regard |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
Manas Biswal Intermediate

Joined: 29 Nov 2002 Posts: 382 Topics: 27 Location: Chennai, India
|
Posted: Tue Jan 10, 2006 9:50 am Post subject: |
|
|
Rama_Prayaga,
Your query and your requirement don't seem to match. Your query will sort all the names in the table and then fetch the first 2000 records from the sorted names.
But your requirement says that you want to fetch the first 2000 records (in any order) and then sort it by name.
What is your exact requirement. The first one makes sense to me but I can't see why you would need it the 2nd way. If you fetch the first 2000 names in any order then whats the need of sorting it afterwards.
Regards,
Manas _________________ There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948) |
|
Back to top |
|
 |
Rama_Prayaga Beginner

Joined: 20 May 2003 Posts: 45 Topics: 15
|
Posted: Wed Jan 11, 2006 7:30 am Post subject: |
|
|
Hi Kolusu,
Thanks for your LINK. I shall go thru it.But Program is a online program , so cannot unload the data.
Hi Manas,
There are Nearly three million rows in a three Tables combined which I have access.I need Distinct Rows 2000 Rows.When I use SELECT DISTINCT then there are performance ISSUEs as it sorts the whole data and then fetch 2000 rows.So i have do a workarounf method.When I Analyised the query I found i get duplicate rows because of one column data has duplicates,
So thoght if I do ORDER BY , then Could just ignore the DUPLICATES programatically.Then realised that even ORDER BY also does a sort on the whole table.
But I wanted a new option If any of the SELECT statement, ORDER BY expression, lets you
specify operators as the sort key for the result table of 2000 rows I fetch first.
Hope I did not confuse you.
KIndly let me know if there is any possibility.
Regards
Rama Krishna Prayaga |
|
Back to top |
|
 |
|
|