MySQL Forums
Forum List  »  Newbie

logical OR on two fields in a table in a database
Posted by: Erin ONeill
Date: June 27, 2005 11:43AM

Hey all!
I'm working on optimizing MySQL and in looking at the slow query log I have a pretty typical and basic query that is doing a FULL table scan -- even though both fields have indexes on them.

What I want to do is see if the variable is equal to either a Username or Email in one TABLE - no table joins here. This is for logging into the site. So the query looks something like this:
Select Username, Email where Username = $user OR Email = $user;

I just want a true or false, I don't really need the username or email.

The table is really large and only going to get larger. Not sure of the syntax for using IN, when I want to test TWO fields??

This doesn't seem to be discussed in optimizing queries (which all use ONE field when discussing the logical OR). I keep reading that the logical OR should be avoided. And let me tell you -- this query is a HOG and too slow!

Any suggestions?

erin

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.