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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL order of operations question

Status
Not open for further replies.

noober

IS-IT--Management
Oct 10, 2003
112
US
Okay, please do not tease the dummy (me)...but does the way a SQL statements criteria filters are ordered affect its performance? For instance if I have 100 client with a sales_tot > 10000 does this:

select * from tbl_sales
where client_code = "0100"
and sales_tot > 10000

--run fast than this:

select * from tbl_sales
where sales_tot > 10000
and client_code = "0100"

Just wondering if since I am limiting the number of possible qulaifying returns based via the specific client ID if the first statement is better than the second? I am sure this is simple learned on the first day type stuff, but I sort of woke up one day needing to know SQL without ever really having any real training.

 
Hi:

The question is what data types are sales_tot and client_code? Apparently they are int, smallint, or perhaps decimal. Using strings requires the engine to perform a string to decimal conversion which is less efficient. Also, if memeory serves me correctly, the conversion forces a full table scan so even if the column(s) are indexed, the index isn't used.

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top