
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Why BINARY keyword used with MySQL REGEXP operator?
Use the BINARY keyword to force REGEXP to match the string as a binary string. We will see the difference here.
Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (0.46 sec)
Insert some records in the table using insert command. We have names here with different cases −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('JOHN'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('john'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('JOhn'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------+ | Name | +------+ | John | | JOHN | | john | | JOhn | +------+ 4 rows in set (0.00 sec)
Here is the query to learn the difference between REGEXP and REGEXP operator with BINARY −
mysql> select Name REGEXP 'JOHN' AS ResultWithOutBinary, Name REGEXP BINARY 'JOHN' AS ResultWithBinary from DemoTable;
Output
This will produce the following output −
+---------------------+------------------+ | ResultWithOutBinary | ResultWithBinary | +---------------------+------------------+ | 1 | 0 | | 1 | 1 | | 1 | 0 | | 1 | 0 | +---------------------+------------------+ 4 rows in set (0.04 sec)
- Related Articles
- What is MySQL REGEXP operator and how it handles pattern matching?
- Does MySQL update with regexp possible?
- How MySQL NULL-safe equal operator performs when used with row comparisons?
- MySQL query for alphabetical search (ABC) with REGEXP?
- What are the different unit values that can be used with MySQL INTERVAL keyword?
- MySQL CREATE statement with KEY keyword
- Fetch info with MySQL EXPLAIN KEYWORD?
- Implement MySQL REGEXP to fetch records with . and numbers
- How to search specific word in MySQL with RegExp?
- What are the different wildcard characters that can be used with MySQL LIKE operator?
- What are the different wildcard characters that can be used with MySQL RLIKE operator?
- What is the use of MySQL BINARY keyword while performing string comparison?
- Perform MySQL update with AND operator
- MySQL XOR operator with IN clause?
- MySQL REGEXP to fetch string + number records beginning with specific numbers?

Advertisements