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? Link to comment https://forums.phpfreaks.com/topic/232344-where-order-of-conditions/ Share on other sites More sharing options...
Maq Posted March 31, 2011 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. Link to comment https://forums.phpfreaks.com/topic/232344-where-order-of-conditions/#findComment-1195272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.