SQL WHERE LIKE Statement
- WHERE LIKE determines if a character string matches a pattern.
- Use WHERE LIKE when only a fragment of a text value is known.
- WHERE LIKE supports two wildcard match options: % and _ .
The SQL WHERE LIKE syntax
The general syntax is:
- SELECT column-names FROM table-name WHERE column-name LIKE value
Optional Wildcard characters allowed in 'value' are % (percent) and _ (underscore).
A % matches any string with zero or more characters.
An _ matches any single character.
SQL WHERE LIKE Examples
1) any string with zero or more characters(%)
mysql> select name from person where name like 's%';
+-----------------+
| name |
+-----------------+
| subham ball |
| sajal |
| sourav biswas |
| sajal |
| shantanu biswas |
| sudip saha |
+-----------------+
6 rows in set (0.00 sec)
+-----------------+
| name |
+-----------------+
| subham ball |
| sajal |
| sourav biswas |
| sajal |
| shantanu biswas |
| sudip saha |
+-----------------+
6 rows in set (0.00 sec)
2) matches any single character(_)
mysql> select name from person where name like 'saja_';
+-------+
| name |
+-------+
| sajal |
| sajal |
+-------+
2 rows in set (0.01 sec)
+-------+
| name |
+-------+
| sajal |
| sajal |
+-------+
2 rows in set (0.01 sec)
Comments
Post a Comment