[thelist] SQL help -- replacing OR to use index

Erick Papadakis erick_papadakis at yahoo.com
Mon Aug 12 19:23:01 CDT 2002


 p.s., if you reply, kindly CC me as well.

hi, i have the following SQL query

  select col1 from table1
  where
  col2 = 'xxx' or col3 = 'xxx'

how can i get rid of this OR? due to my table design and the logic
involved, i have to check both these 2 columns (in a search function). i
cannot concaneate them to make a third column because i need to check for
exact match but for both the columns.

the EXPLAIN in mysql gives me the "ALL" type, which of course is not
optimal. if i remove the OR in the above SQL, and make only one
condition, then this EXPLAIN comes back as "const". this is ideal! and
what i want.

so what can i do to replace the OR? in a curious fit i tried :

  select col1 from table1
  where
  'xxx' in (col2, col3)

and to my surprise this works!!! but the EXPLAIN returns "ALL" again. so
it is useless..

thanks in advance for any insight/ideas!

.ep



__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



More information about the thelist mailing list