MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

select WITH ORDER BY expresion

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Mon Jan 09, 2006 2:36 pm    Post subject: select WITH ORDER BY expresion Reply with quote

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
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Jan 09, 2006 3:04 pm    Post subject: Reply with quote

Ramya_prayaga,

Do you have an index defined on NAME column? Run an explain and see if the query is going for a tablespace scan.

Check this link for Evaluating SQL queries

http://www.mvsforums.com/helpboards/viewtopic.php?t=587&highlight=sql

Another option is to unload the data using unload utility and read that file in the program.

Hope this helps..

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Tue Jan 10, 2006 9:50 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Wed Jan 11, 2006 7:30 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group