This is actually a neat little peice of MYSQL code. It enables you to select only rows that start with the given regular expression. In this case, any names that start with the letter 'M' (not case sensitive).
mysql> select * from People;
+----------+-------+------+------------+
| Name | Color | Sex | DOB |
+----------+-------+------+------------+
| Boris | Blue | m | 1980-03-22 |
| Barry | Red | m | 1919-04-09 |
| Belinda | Green | f | 1988-01-04 |
| Paul | Red | m | 1988-02-18 |
| Mike | Green | m | 1979-05-25 |
| Morris | White | f | 1971-01-12 |
+----------+-------+------+------------+
6 rows in set (0.01 sec)
mysql> /*Select names beginning with 'm'. Uses '^' to match the beginning of the name*/
mysql> SELECT * FROM People WHERE name REGEXP '^M';
+----------+-------+------+------------+
| Name | Color | Sex | DOB |
+----------+-------+------+------------+
| Mike | Green | m | 1979-05-25 |
| Morris | White | f | 1971-01-12 |
+----------+-------+------+------------+
2 row in set (0.02 sec)
See, simple.
Posted by OLLIE at 21:45pm
No comments yet. Be the first to add one!