Where Clause - LIKE and IN

  • 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%'

  • 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.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thanks, that worked

    select *

    from table

    where (location IN ('1234', '2456', '4567', '4567')

    OR location LIKE '90%')

  • Great. You may also want to consider adding an index on the location column to prevent table scans.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply