Home >Database >Mysql Tutorial >Usage of % in mysql
The % symbol in MySQL is a wildcard character used to match any sequence of characters in LIKE query conditions. Start a fuzzy match: % is placed at the beginning of a string to match any value that begins with that string. Ending fuzzy matching: % is placed at the end of a string to match any value that ends with that string. Match any character or string: % placed in the middle of a string matches any value that contains the string.
Usage of % in MySQL
The role of % symbol
The % symbol in MySQL is a wildcard character used to match any sequence of characters in the LIKE query condition.
Usage
In LIKE query conditions, you can use the % symbol to match the following types of data:
LIKE '%john'
will match "john doe", "john smith", etc. LIKE 'smith%'
will match "john smith", "jane smith", etc. LIKE '%or%ger'
will match "morgan", "orange", etc. Examples
Here are some examples of fuzzy matching using the % wildcard:
SELECT * FROM users WHERE name LIKE '%john%';
Find all name column values that contain the string "john". SELECT * FROM products WHERE description LIKE '%apple%';
Find all description column values that contain the string "apple". SELECT * FROM orders WHERE order_id LIKE 'OR%';
Find all order_id column values starting with "OR". Note
The above is the detailed content of Usage of % in mysql. For more information, please follow other related articles on the PHP Chinese website!