Select From Where Like: Customers City

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

 % - The percent sign represents zero, one, or multiple characters

The following SQL statement selects all customers with a City starting
with "ber":

SELECT * FROM Customers


WHERE City LIKE 'ber%';

 _ - The underscore represents a single character

The following SQL statement selects all customers with a City starting
with any character, followed by "erlin":

SELECT * FROM Customers


WHERE City LIKE '_erlin';

 [charlist] - Defines sets and ranges of characters to match

The following SQL statement selects all customers with a City starting
with "L", followed by any character, followed by "n", followed by any
character, followed by "on":

SELECT * FROM Customers


WHERE City LIKE 'L_n_on';

 [^charlist] or [!charlist] - Defines sets and ranges of characters NOT to


match

The following SQL statement selects all customers with a City starting
with "b", "s", or "p":

SELECT * FROM Customers


WHERE City LIKE '[bsp]%';
The following SQL statement selects all customers with a City starting with "a",
"b", or "c":

SELECT * FROM Customers


WHERE City LIKE '[a-c]%';

The two following SQL statements select all customers with a City NOT starting
with "b", "s", or "p":

SELECT * FROM Customers


WHERE City LIKE '[!bsp]%';
OR

SELECT * FROM Customers


WHERE City NOT LIKE '[bsp]%';

You might also like