How to use wildcard search in mysql?

In MySQL, you can use the LIKE operator to perform a fuzzy search. LIKE operator is used to match patterns in a query, and wildcards can be used to represent parts of the pattern. Here are some examples of performing fuzzy searches using the LIKE operator:

  1. Search for data that starts with a specified string:
SELECT * FROM 表名 WHERE 列名 LIKE '指定字符串%'
  1. Search for data that ends with a specified string.
SELECT * FROM 表名 WHERE 列名 LIKE '%指定字符串'
  1. Search for data containing the specified string.
SELECT * FROM 表名 WHERE 列名 LIKE '%指定字符串%'
  1. Retrieve data that contains specified characters at a specific location.
SELECT * FROM 表名 WHERE 列名 LIKE '_指定字符%'

The underline (_) represents a wildcard character for one character.

  1. Search for data that does not start with the specified string.
SELECT * FROM 表名 WHERE 列名 NOT LIKE '指定字符串%'

It is important to note that the LIKE operator is case-sensitive. If you want to do a case-insensitive fuzzy query, you can use the LOWER or UPPER function to convert the column name and specified string to the same case. For example:

SELECT * FROM 表名 WHERE LOWER(列名) LIKE LOWER('指定字符串%')
bannerAds