Home  >  Article  >  Database  >  Does mysql support like?

Does mysql support like?

青灯夜游
青灯夜游Original
2020-10-06 07:38:202238browse

mysql supports like, which can match any multi-character or fuzzy match any single character, and will be used in combination with "%" and "_"; for example, "%a" matches data ending with a, " %a%" matches data containing a, "_a_" matches data with three digits and the middle letter is a, etc.

Does mysql support like?

Using Like in MySQL for fuzzy query

The so-called "fuzzy query" corresponds to the "precise query" Come. For example, if we want to query whether a field value is equal to 1, we can write "where column=1" in the SQL statement. This is an exact query. Precise query is very simple and easy to understand, but we often use fuzzy query. For example, I want to query a user from the user table, but I can't remember his name. I only know that there is "Hong" in his name. words, then fuzzy query comes in handy.

like match/fuzzy match, will be used in combination with % and _.

'%a'     //以a结尾的数据
'a%'     //以a开头的数据
'%a%'    //含有a的数据
'_a_'    //三位且中间字母是a的
'_a'     //两位且结尾字母是a的
'a_'     //两位且开头字母是a的

Query information starting with the java field.

SELECT * FROM position WHERE name LIKE 'java%';

Query information containing java fields.

SELECT * FROM position WHERE name LIKE '%java%';

Query information ending with java field.

SELECT * FROM position WHERE name LIKE '%java';

Recommended tutorial: mysql video tutorial

The above is the detailed content of Does mysql support like?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn