In MySQL, wildcards are special characters used in conjunction with the LIKE operator in a WHERE clause to perform pattern matching in string comparisons.
Here are the commonly used wildcards:
Represents zero or more characters.
SELECT * FROM products WHERE product_name LIKE 'Tab%';
Note: This query retrieves all columns from the "products" table where the "product_name" starts with 'Tab'.
SELECT * FROM products WHERE product_name LIKE 'BAL_';
Represents a single character.
Note: This query retrieves all columns from the "products" table where the "product_name" starts with 'BAL' followed by any single character.
SELECT * FROM products WHERE product_name LIKE 'Desk[1-3]%'; SELECT * FROM products WHERE product_code NOT LIKE '[AE]%';
[]: Represents any single character within the specified range.
[^]: Represents any single character not in the specified set.
[]: This query retrieves all columns from the "products" table where the "product_name" starts with 'Desk' followed by a digit between 1 and 3.
[^]: This query retrieves all columns from the "products" table where the "product_code" does not start with 'A' or 'E'.