Results 1 to 5 of 5
Thread: Index when using OR?
Dec 3, 2008, 11:01 #1
- Join Date
- Jun 2007
- 0 Post(s)
- 0 Thread(s)
Index when using OR?
Let's say I have a private message table like this:
SELECT id , uid1 , uid2 , msg , msgdate FROM user_pm WHERE uid1 = 999 OR uid2 = 999 ORDER msgdate DESC LIMIT 10
I have a similar setup which will need to be searched through on every page refresh (not PM) so for that query I'd want to use indexes.
Should I just do two separate queries, WHERE uid1=999 and another one with uid2=999 (with an index on each column), and then do some sorting in php (will probably need to set a higher LIMIT to actually get *close to* everything), or is there a better way?