Home
WHERE clauses should not contain redundant conditions
Description
The "WHERE clauses should not contain redundant conditions" code rule states that WHERE clauses should not contain conditions that are unnecessary or redundant. This means that the WHERE clause should only contain conditions that are necessary for the query to return the desired results. Redundant conditions can lead to inefficient query execution as the engine will need to process them unnecessarily. Furthermore, redundant conditions can lead to incorrect query results if the conditions are not logically equivalent. It is therefore important to ensure that the WHERE clause contains only the necessary conditions.
Key Benefits
- Reduced complexity: WHERE clauses should not contain redundant conditions to avoid unnecessary complexity in the query.
- Improved performance: By avoiding redundant conditions, the query can be optimized and executed more efficiently.
- Increased accuracy: Redundant conditions can lead to incorrect results, so avoiding them helps ensure accuracy.
Non-compliant Code Example
SELECT Product.ProductID,
Product.Name,
Color
FROM Production.Product
WHERE ListPrice > 50 AND ListPrice = 200; --Non compliant code (Where clause is having redundant conditions)
Compliant Code Example
SELECT Product.ProductID,
Product.Name,
Color
FROM Production.Product
WHERE ListPrice > 50; --Compliant code (Where clause is not having redundant conditions)
