xiao Posted April 15, 2008 Share Posted April 15, 2008 Hi, I was wondering if anyone knows an advanced tutorial about mysql wildcards. I want to search a string of 6 characters with for example the first 2 characters being anything, then "AP" and then another 2 chracters. Do I search like this? WHERE something LIKE '__AP__' Because when I'd search like this: WHERE something LIKE '%AP%' I'd get results like BAPRS4, 9GLAP0, ... Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 try: WHERE SUBSTR(something,3,2) = 'AP' Quote Link to comment Share on other sites More sharing options...
xiao Posted April 15, 2008 Author Share Posted April 15, 2008 oh, so multiple underscores won't work? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 I've never used or seen someone use an underscore as a wildcard before Quote Link to comment Share on other sites More sharing options...
xiao Posted April 15, 2008 Author Share Posted April 15, 2008 I found it while searching for wildcard. I just found this: http://www.htmlite.com/mysql011.php It says: The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of 'Stan' plus 3 characters (since there are 3 underscores)... $sql = mysql_query("SELECT * FROM address_book WHERE last_name LIKE 'Stan___'"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; } So I guess multiple underscores will work Quote Link to comment Share on other sites More sharing options...
gluck Posted April 15, 2008 Share Posted April 15, 2008 I found it while searching for wildcard. I just found this: http://www.htmlite.com/mysql011.php It says: The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of 'Stan' plus 3 characters (since there are 3 underscores)... $sql = mysql_query("SELECT * FROM address_book WHERE last_name LIKE 'Stan___'"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; } So I guess multiple underscores will work should work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.