Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : Web Architecture : Education - Tutorials
Writing efficient PHP
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
4. Optimizing database queries
  


Eliminating any unnecessary ORDER BY clauses page 3 of 8


You can also reduce database read time by eliminating unnecessary ORDER BY clauses in your SQL queries. For example, consider the following SELECT statement designed to retrieve the product name and price when given a product number.


SELECT product_name, price
FROM catalog
WHERE product_num = "123456789"
ORDER BY product_name

Assuming the product number is unique for all products in the catalog, this query only returns a maximum of one record. Even though sorting 0 or 1 records should be very quick, the ORDER BY clause is actually redundant. When this query is executed hundreds or thousands of times for different products, this redundant overhead can add up. Eliminate this type of redundancy.


Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact