Brian W Posted March 31, 2011 Share Posted March 31, 2011 I know that LIKE conditions are slower than a strait equals conditions. In the case that I'm trying to find a particular user's information and I know their first name, I could do something like: SELECT * FROM users WHERE name LIKE '$name%'; And if I knew their state too: SELECT * FROM users WHERE state_id = '$state_id' AND name LIKE '$name%'; The Question is: I would expect that because the state condition comes first, MySQL would only run the LIKE condition on the dataset that matched the state which should increase the speed. Am I correct? Quote Link to comment https://forums.phpfreaks.com/topic/232344-where-order-of-conditions/ Share on other sites More sharing options...
Solution Maq Posted March 31, 2011 Solution Share Posted March 31, 2011 I would expect that because the state condition comes first, MySQL would only run the LIKE condition on the dataset that matched the state which should increase the speed. Am I correct? From what I understand, yes, you are correct. To be sure, run it a few times with/out the WHERE clause and do a time comparison. Quote Link to comment https://forums.phpfreaks.com/topic/232344-where-order-of-conditions/#findComment-1195272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.