JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

Enforce case sensitivity in MySQL LIKE

Author:JIYIK Last Updated:2025/04/22 Views:

Keywords in any programming language such as C, C++, Java, and MySQL are useful; they are called reserved words. These reserved words have meanings and functions.

When these keywords are used in a statement, they operate according to their predefined behavior.

Select, Deleteand Whereare examples of reserved keywords. Based on the agreement decided before implementation, these words are displayed in the declaration and action is taken accordingly.

Table and variable names can never be similar to keywords, as they are reserved. No one can programmatically use these keywords in programming practice.


LikeEnforce case sensitivity of keywords in MySQL

likeThe keyword in MySQL whereis used with the keyword. Its function is to match a specific pattern.

Use wildcards or glob characters to identify these patterns.

In programming languages, a wildcard is a symbol that has a meaning and is used for pattern recognition. There are two types of wildcards used in MySQL.

These symbols can be used liketo group and combine in clauses.

LIKEThe syntax of the keyword:

SELECT * FROM table_name WHERE column_name LIKE 'ABC_';
SELECT * FROM table_name WHERE column_name LIKE 'T_ST%';

The above syntax uses likekeywords and wildcard characters to search for some defined set of values ​​from a table.

likeThe nature of the operation is that it ignores the case of the words and tries to find a match.

likeOne way to implement a case-sensitive comparison using :

If the user requires wherea more exact case-sensitive match in the clause, use LIKE BINARYthe keyword.

Query and execute MySQL statement:

 select * from stu;
+------+---------+------------+
| id   | Name    | DOB        |
+------+---------+------------+
| 111  | Amit    | 1970-01-08 |
| 112  | Shushma | 0000-00-00 |
| 113  | Rami    | 2020-09-08 |
| 114  | Sam     | 2020-09-08 |
| 115  | tonny   | 2020-09-08 |
+------+---------+------------+

Refer to the table above like binaryfor the following two queries using the keyword.

Select * from stu where name LIKE BINARY 's%';
Select * from stu where name LIKE BINARY '%mi_';

The above query lists all the occurrences of the column name with characters between them mi. BINARYThe keyword acts as a case sensitive match lookup in the query.

%The and _special characters stuhave special meanings when finding matches for all result sets in the table.

The first query shows selectthat the query results in all rows namewhere the column sstarts with lowercase . Therefore, the first query has no output.

Likewise, when %mi_the query is tried again using the character, only one result is displayed, as shown in the following image.

The screenshot of the actual execution of the above query in MySQL is as follows.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Changing max_allowed_packet Size in MySQL Server

Publish Date:2025/04/22 Views:192 Category:MySQL

This article explains how to change the max_allowed_packet size in MySQL server. To understand this, we will use two operating systems, Windows 10 and Linux (Ubuntu). Changing max_allowed_packet Size in MySQL Server If we try to upload a fi

Zerofill usage, advantages and alternatives in MySQL

Publish Date:2025/04/22 Views:195 Category:MySQL

In this article we will understand the uses, advantages and alternatives of ZEROFILL attribute in MySQL. Use and benefits of the ZEROFILL attribute in MySQL The benefit of using the ZEROFILL attribute is that it has nothing to do with input

Compare only MySQL timestamp dates to date parameters

Publish Date:2025/04/22 Views:64 Category:MySQL

In this article we will use the DATE() , CAST() , and CONVERT() functions to compare MySQL timestamp dates with only the date parameter. DATE() vs. CAST() vs. CONVERT() in MySQL Below is a brief description of each function. You can also fi

Calculating Percentages in MySQL

Publish Date:2025/04/22 Views:66 Category:MySQL

We will use one or more columns to calculate percentages in MySQL. There are different ways to do this, and for each method we will use an example table. Calculate percentage using a column in MySQL We have a table called sales where ID, Re

Selecting multiple values using WHERE in MySQL

Publish Date:2025/04/22 Views:185 Category:MySQL

This article is about using MySQL query to get data from a specific table or relation that satisfies a specific condition. To do this, the WHERE clause is used in the SQL query. WHERE clause in SQL query WHERE The clause specifies the condi

Changing the connection timeout in MySQL

Publish Date:2025/04/22 Views:59 Category:MySQL

We are learning how to change the connection timeout in MySQL using Linux (Ubuntu 20.04) and Windows operating systems. Changing the connection timeout in MySQL Sometimes you keep losing connection to the MySQL server because the connect_ti

MySQL fix Data Is Truncated for a Column error

Publish Date:2025/04/22 Views:101 Category:MySQL

This article describes possible causes and solutions for the MySQL error Data is truncated for a column . Fix data truncated due to column error in MySQL Here, we will discuss the possible causes and solutions to eliminate MySQL data trunca

MySQL Error Server PID File Could Not Be Found Solution

Publish Date:2025/04/22 Views:192 Category:MySQL

In this article, we will study about the Error! Error Server PID File Could Not Be Found! in MySQL and its solution with full explanation. MySQL PID file The file that contains the process identification number or process ID of a running My

Get the last inserted ID using PHP MySQLi function

Publish Date:2025/04/22 Views:99 Category:MySQL

This article briefly introduces the PHP mysqli() function and demonstrates how to use it to get the last inserted ID from a MySQL database. PHP mysqli() Function It is an extended version of the MySQL driver called mysqli and is typically u

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial