Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement order matter?

Status
Not open for further replies.

kovas

Technical User
Aug 6, 2002
88
US
Does the order of your select statement make the report load faster?

In example, lets say I am trying to select where ID = 5 and Name = CD.

I have 10,000 recs with ID of 5 and out of those 100 have a name of CD.

would (Name = CD and ID = 5) load faster than (ID = 5 and Name = CD), or it doesnt matter at all?

thanks


 
Putting the indexed fields first might spped things up in some PC database environments, but I wouldn't expect to make a difference in any of the standard SQL environments. What is your database? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I think that this depends on several things, some of which are the database, the cardinality of the Name and ID fields, and the type (existence) of indexing.

Since you are testing only 2 conditions, you're probably best served by running a few tests.

-k kai@informeddatadecisions.com
 
Although I am somewhat of a novice compared to many responses here, I have had good success (as mentioned earlier)by determining what the indexed field or fields are if they exist, then using them in the "where" statement (not the select statement)even if I simply say for example

Select field35, field42
from TableA
Where fieldA is not null
AND fieldB is not null

This is for when fieldA and fieldB make up an index.

I would welcome any fine tuning/corrections to my suggestion here because I am interested also in improving performance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top