homepage Welcome to WebmasterWorld Guest from 54.211.47.170
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
SQL - Combining 'LIKE' and 'IN' operators?
combining the functinality of both
Argblat




msg:1580987
 8:35 pm on Oct 25, 2005 (gmt 0)

Is it possible to combine the functionalities of the LIKE operator and the IN operator into one function?

example: (how do I make this concept into a functional query)

Select * from table1 where PhoneNumber IN ("%1234", "%5678");

This query will not return any results becuase, given the syntax, it will search for the literal string "%1234" instead of treating it as a wildcard operator as it would with a LIKE statement

thank you
-Mike

 

zCat




msg:1580988
 8:47 pm on Oct 25, 2005 (gmt 0)

Select * from table1 where PhoneNumber IN ("%1234", "%5678");

You don't say which database you're using (MySQL judging by the double quotes), but with all the usual suspects the simplest, SQL-ish way to do this is with OR:

Select * from table1 where PhoneNumber LIKE "%1234" OR PhoneNumber LIKE "%5678"

If you have further conditions in the where clause, use brackets, e.g.
Select * from table1 where (PhoneNumber LIKE "%1234" OR PhoneNumber LIKE "%5678") AND widget="blue"

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved