Does the order of conditions matter if we have more than one in a query?


#1

Question

Does the order of conditions matter if we have more than one in a SQL query?

Answer

No, the order of conditions within a query should not matter, and will not affect the result set.

If you use the same conditions following the WHERE clause and combined using AND in any order, then the query will always return the intersection of all the conditions.

For example, the following queries will return the same results,

SELECT *
FROM table
WHERE condition_1
AND condition_2;

SELECT *
FROM table
WHERE condition_2
AND condition_1;