Tuesday, December 31, 2013

Use of REGEXP operator.

Consider we have a table called person_tbl and it's having a field called name:
Query to find all the names starting with 'st'
mysql> SELECT name FROM person_tbl WHERE name REGEXP '^st';
Query to find all the names ending with 'ok'
mysql> SELECT name FROM person_tbl WHERE name REGEXP 'ok$';
Query to find all the names, which contain 'mar'
mysql> SELECT name FROM person_tbl WHERE name REGEXP 'mar';
Query to find all the names starting with a vowel and ending with 'ok'
mysql> SELECT name FROM person_tbl WHERE name REGEXP '^[aeiou]|ok$';

No comments:

Post a Comment