Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match one character in MySQL in place of %?

Tags:

mysql

In the following SQL:

SELECT * FROM X WHERE Y LIKE "%s"; 

the % will match any characters before an s. The % can be x, xx, xrf, etc.

Is there any symbol that will only match one character, like:

SELECT * FROM X WHERE Y LIKE "?s" 

where ? will match only one character like a, b, c, etc.?

like image 215
Mazhar Ahmed Avatar asked Mar 09 '11 15:03

Mazhar Ahmed


People also ask

How do I match a character in SQL?

SQL pattern matching enables you to use _ to match any single character and % to match an arbitrary number of characters (including zero characters). In MySQL, SQL patterns are case-insensitive by default. Some examples are shown here. Do not use = or <> when you use SQL patterns.

How do I match data in MySQL?

Example - Equality Operator In MySQL, you can use the = operator to test for equality in a query. The = operator can only test equality with values that are not NULL. For example: SELECT * FROM contacts WHERE last_name = 'Johnson';

What is the wildcard character in MySQL?

A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

Does MySQL have Ilike?

In MySQL you do not have ILIKE. Checkout MySQL docs on string comparison functions.


1 Answers

You want to use an underscore (_) character. See the documentation here.

like image 124
Joe Stefanelli Avatar answered Sep 28 '22 05:09

Joe Stefanelli