Home >Database >Mysql Tutorial >How to use like in mysql
The LIKE operator is used for pattern matching in MySQL. It uses wildcards to match character sequences, including: %: matches zero or more characters. _: Matches a single character. [ ]: Matches any characters listed within square brackets.
Usage of LIKE operator in MySQL
The LIKE operator is used for pattern matching in MySQL. It allows you to find values that match a specific pattern, which can contain wildcard characters.
Wildcard:
Syntax:
<code class="sql">SELECT column_name FROM table_name WHERE column_name LIKE 'pattern';</code>
Example:
Find all names starting with "John":
<code class="sql">SELECT name FROM customers WHERE name LIKE 'John%';</code>
Find all names containing the letter "a":
<code class="sql">SELECT name FROM customers WHERE name LIKE '%a%';</code>
Find all names starting with "John" and ending with "son":
<code class="sql">SELECT name FROM customers WHERE name LIKE 'John%son';</code>
Tips:
The above is the detailed content of How to use like in mysql. For more information, please follow other related articles on the PHP Chinese website!