Wildcard characters

suggest change

Wildcard characters are used with LIKE.

% and \_ are widely supported. [charlist] and [^charlist] are SQL Server.

% - A substitute for zero or more characters

-- City starting with "Lo"
SELECT * FROM Customers
WHERE City LIKE 'Lo%';

-- City containing "es"
SELECT * FROM Customers
WHERE City LIKE '%es%';

_ - A substitute for a single character

-- City starting with any one character, followed by "erlin"
SELECT * FROM Customers
WHERE City LIKE '_erlin';

[charlist] - Sets and ranges of characters to match

-- City starting with "a", "d", or "l"
SELECT * FROM Customers
WHERE City LIKE '[adl]%';

-- City starting with "a", "b", or "c"
SELECT * FROM Customers
WHERE City LIKE '[a-c]%';

[^charlist] - Matches only a character NOT specified within the brackets

-- City starting with a character that is not "a", "p", or "l"
SELECT * FROM Customers
WHERE City LIKE '[^apl]%';
-- also SQL Server: one or more characters, and not starting with a, p, or l
SELECT * FROM Customers
WHERE City NOT LIKE '[apl]%' AND City LIKE '_%';

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents