November 23, 2010 at 9:39 am
What is the best way to modify a WHERE clause to include the condition LIKE and IN. Using the example script below, nothing is selected. What do I need to do to modify the script to select the condition IN and LIKE?
select *
from table
where location IN ('1234', '2456', '4567', '4567')
and location LIKE '90%'
November 23, 2010 at 9:47 am
This is not returning results because your IN and your LIKE conditions conflict with each other. It looks to me, without seeing sample data, that you just need to change your AND to an OR and you'll be good to go.
If that does not work, please provide some sample data and an example of the result set you'd like your SELECT to return.
November 23, 2010 at 10:56 am
Thanks, that worked
select *
from table
where (location IN ('1234', '2456', '4567', '4567')
OR location LIKE '90%')
November 23, 2010 at 12:17 pm
Great. You may also want to consider adding an index on the location column to prevent table scans.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply