I wanted to get some clarification, if using OR in a sql statement on indexes does it use the index or no?
For example if I have this query:
SELECT * FROM account_orders WHERE accountid = 1 OR accountid = 0
I have an index on the accountid field
Will mysql use the index? Or would it be better to use a union? I keep reading that mysql doesnt use an index with an or statement, or perhaps Im reading that incorrectly. Any help/explanation would be helpful. Using mysql 5.x
Database won’t use an index if you use
ORlike you have.The work around is to rephrase it using
IN. as follows:Databases will use an index (if available) with this syntax