Database Reference
In-Depth Information
• Strings that end with a particular substring:
mysql> SELECT name FROM metal WHERE name LIKE '%d';
+------+
| name |
+------+
| gold |
| lead |
+------+
• Strings that contain a particular substring at any position:
mysql> SELECT name FROM metal WHERE name LIKE '%in%';
+----------+
| name |
+----------+
| platinum |
| tin |
+----------+
• Strings that contain a substring at a specific position (the pattern matches only if
at occurs at the third position of the name column):
mysql> SELECT name FROM metal where name LIKE '__at%';
+----------+
| name |
+----------+
| platinum |
+----------+
An SQL pattern matches successfully only if it matches the entire comparison value. Of
the following two pattern matches, only the second succeeds:
'abc' LIKE 'b'
'abc' LIKE '%b%'
To reverse the sense of a pattern match, use NOT LIKE . The following statement finds
strings that contain no i characters:
mysql> SELECT name FROM metal WHERE name NOT LIKE '%i%';
+---------+
| name |
+---------+
| gold |
| lead |
| mercury |
+---------+
SQL patterns do not match NULL values. This is true both for LIKE and for NOT LIKE :
Search WWH ::




Custom Search