MySQL/Tutorials: Difference between revisions
< MySQL
Jump to navigation
Jump to search
imported>Eric Evers m (→Exercises) |
imported>Eric Evers m (→Using RegExp) |
||
Line 13: | Line 13: | ||
Lets create a simple table. | Lets create a simple table. | ||
CREATE table | CREATE table word (name varchar(20)); | ||
INSERT into | INSERT into word VALUES ("people"),("places"),("things"),("ppl"); | ||
SELECT * FROM | SELECT * FROM word; | ||
+--------+ | +--------+ | ||
| name | | | name | | ||
Line 28: | Line 28: | ||
Look for two p's in a row. | Look for two p's in a row. | ||
SELECT * FROM | SELECT * FROM word WHERE name RegExp "[p]{2}" | ||
+--------+ | +--------+ | ||
| name | | | name | | ||
Line 37: | Line 37: | ||
A "." is any character. | A "." is any character. | ||
A "+" is one or more copies of a character. | A "+" is one or more copies of a character. | ||
A "C{n}" looks for n copies of C. | |||
Look for two p's but not next to one another. | Look for two p's but not next to one another. | ||
SELECT * FROM | SELECT * FROM word WHERE name RegExp "p.+p" | ||
+--------+ | +--------+ | ||
| name | | | name | | ||
Line 50: | Line 51: | ||
Give a sql regular expression query that will select: | Give a sql regular expression query that will select: | ||
1) only | 1) only things | ||
2) only ppl and places | 2) only ppl and places | ||
3) only people and places | 3) only people and places | ||
4) only things and places | 4) only things and places |
Revision as of 13:44, 5 March 2008
MySQL tutorial
Intall
Create User
Create Database
Queries
String functions
Pattern Matching
Using Like
Using RegExp
Regular expressions in SQL
Lets create a simple table.
CREATE table word (name varchar(20)); INSERT into word VALUES ("people"),("places"),("things"),("ppl");
SELECT * FROM word; +--------+ | name | +--------+ | people | | places | | things | | ppl | +--------+
Look for two p's in a row.
SELECT * FROM word WHERE name RegExp "[p]{2}" +--------+ | name | +--------+ | ppl | +--------+
A "." is any character. A "+" is one or more copies of a character. A "C{n}" looks for n copies of C. Look for two p's but not next to one another.
SELECT * FROM word WHERE name RegExp "p.+p" +--------+ | name | +--------+ | people | +--------+
Exercises
Give a sql regular expression query that will select:
1) only things 2) only ppl and places 3) only people and places 4) only things and places