The LIKE statement in SQL is used to match strings based on a pattern. It uses the % and _ wildcard characters to match zero or more characters and a single character respectively. The syntax of the LIKE statement is: SELECT * FROM table_name WHERE column_name LIKE 'pattern'.
LIKE statement in SQL
The LIKE statement is used in SQL to match strings based on patterns. This statement uses wildcard characters (% and _) to represent any character or any single character.
Syntax
<code>SELECT * FROM table_name WHERE column_name LIKE 'pattern';</code>
Wildcards
Usage
Find characters containing a specific string Record
<code>SELECT * FROM table_name WHERE column_name LIKE '%string%';</code>
Example: Find records containing the string "John"
<code>SELECT * FROM customers WHERE name LIKE '%John%';</code>
Find records starting with a specific string
<code>SELECT * FROM table_name WHERE column_name LIKE 'string%';</code>
Example: Find records starting with the string "Smith"
<code>SELECT * FROM customers WHERE name LIKE 'Smith%';</code>
Find records ending with a specific string
<code>SELECT * FROM table_name WHERE column_name LIKE '%string';</code>
Example: Find records ending with the string "Jones" Records
<code>SELECT * FROM customers WHERE name LIKE '%Jones';</code>
Find records that do not contain a specific string
You can use the NOT LIKE operator to find records that do not contain a specific string.
<code>SELECT * FROM table_name WHERE column_name NOT LIKE 'pattern';</code>
Example
Find records that do not contain the "A" character:
<code>SELECT * FROM table_name WHERE column_name NOT LIKE '%A%';</code>
The above is the detailed content of How to write like statement in sql. For more information, please follow other related articles on the PHP Chinese website!