Controlling Case Sensitivity in Pattern Matching. By default, LIKE is not case sensitive: : Like « Regular Expression « SQL / MySQL






Controlling Case Sensitivity in Pattern Matching. By default, LIKE is not case sensitive:

       
mysql>
mysql> CREATE TABLE mytable
    -> (
    ->  name    VARCHAR(20)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO mytable (name)
    ->  VALUES
    ->          ('copper'),
    ->          ('gold'),
    ->          ('iron'),
    ->          ('lead'),
    ->          ('mercury'),
    ->          ('platinum'),
    ->          ('silver'),
    ->          ('tin')
    -> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql>
mysql> SELECT * FROM mytable;
+----------+
| name     |
+----------+
| copper   |
| gold     |
| iron     |
| lead     |
| mercury  |
| platinum |
| silver   |
| tin      |
+----------+
8 rows in set (0.00 sec)

mysql>
mysql> SELECT name, name LIKE '%i%', name LIKE '%I%' FROM mytable;
+----------+-----------------+-----------------+
| name     | name LIKE '%i%' | name LIKE '%I%' |
+----------+-----------------+-----------------+
| copper   |               0 |               0 |
| gold     |               0 |               0 |
| iron     |               1 |               1 |
| lead     |               0 |               0 |
| mercury  |               0 |               0 |
| platinum |               1 |               1 |
| silver   |               1 |               1 |
| tin      |               1 |               1 |
+----------+-----------------+-----------------+
8 rows in set (0.00 sec)

mysql>
mysql> drop table mytable;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
    
  








Related examples in the same category

1.Where clause: like and %
2.To get the equivalent with LIKE, you'd have had to use % wildcards at the end:
3.like B%
4.like %r
5.LIKE '%e_'
6.Like and concat
7.Like and escape
8.LIKE '%is%'
9.LIKE '______' (underscore)
10.LIKE '______%' (underscore and %)
11.LIKE '_r%r_'
12.LIKE '_@%%@%_' ESCAPE '@'
13.To reverse the sense of a pattern match, use NOT LIKE.
14.SQL patterns do not match NULL values. This is true both for LIKE and NOT LIKE
15.LIKE Search Pattern
16.Pattern Matching: LIKE and %