LIKE¶
Grammar Description¶
The LIKE operator is used to search for specified patterns in columns in the WHERE clause.
There are two wildcards that are often used with the LIKE operator:
Percent sign
%wildcard: means matching any character sequence (including empty character sequence).text%: Matches a string starting with “text”.
Underscore
_wildcard: means matching a single character.te_t: Can match “text”, “test”, etc.
Other characters: The
LIKEoperator is case sensitive to other characters.
Grammar Structure¶
> SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Example¶
drop table t1;
create table t1(a varchar(20));
insert into t1 values ('abc'), ('ABC'), ('abC');
select * from t1 where a like '%abC%';
mysql> select * from t1 where a like '%abC%';
+------+
| a |
+------+
| abC |
+------+
1 row in set (0.00 sec)