SQL WILDCARDS

Wildcards characters are special characters that are used for special searches, for example, searching for words beginning with a particular letter (letter%) or that contain the letter a (%a%), or containing a vowel ([aeiou]).

Wildcards characters are used with the SQL LIKE operator in a judgment SELECT.

Wildcards characters are :

%Replaces zero or more characters
_Replaces any one character
[list] Replaces any character in the list
[^list] o [!list] Replaces any character except the characters in the list

Examples Wildcards

Given the following table 'people'

namesurnamenickname
HARRYCLARKWHITE
HARRYSMITHJOHNSON
JOHNBROWNANDERSON

Select the people whose name contains an 'O'

SELECT * FROM people WHERE name LIKE '%O%'

Result:

namesurnamenickname
JOHNBROWNANDERSON

Select the people whose surname begins with 'CL'

SELECT * FROM people WHERE surname LIKE 'CL%'

Result:

namesurnamenickname
HARRYCLARKWHITE

Select the people whose surname begins with C or S

SELECT * FROM people WHERE surname LIKE '[CS]%'

Result:

namesurnamenickname
HARRYCLARKWHITE
HARRYSMITHJOHNSON