Suppose I have a MySQL query with two conditions:
SELECT * FROM `table` WHERE `field_1` = 1 AND `field_2` LIKE '%term%';
The first condition is obviously going to be a lot cheaper than the second, so I’d like to be sure that it runs first, limiting the pool of rows which will be compared with the LIKE clause. Do MySQL query conditions run in the order they’re listed or, if not, is there a way to specify order?
MySQL has an internal query optimizer that takes care of such things in most cases. So, typically, you don’t need to worry about it.
But, of course, the query optimizer is not foolproof. So…
Sorry to do this to you, but you’ll want to get familiar with
EXPLAINif you suspect that a query may be running less efficiently than it should.http://dev.mysql.com/doc/refman/5.0/en/explain.html