SQL wildcard: SQL wildcard can override one or more characters when searching for data in a database. SQL wildcard characters must be used with the LIKE operator. In SQL, you can use the following wildcard characters:
Wildcard characters |
Describe |
% |
Override one or more characters |
_ |
Replaces only one character |
[Charlist] |
Any single character of the word columns |
[^charlist] or [!charlist] |
Any single character that is not in the word columns |
--The "Persons" table selects people living in a city that starts with "Ne"SELECT * fromPersonsWHERECity like 'ne%'--The "Persons" table selects people living in cities that contain "Lond "SELECT * fromPersonsWHERECity like '%lond%'--The person whose first character in the "Persons" table is followed by "Eorge "SELECT * fromPersonsWHEREFirstName like '_eorge'--The last name of the record selected in the "Persons" table starts with "C", then an arbitrary character, then "R", then any character, then "ER"SELECT * fromPersonsWHERELastName like 'C_r_er'--The "Persons" table selects people who live in cities that start with "A" or "L" or "N"SELECT * fromPersonsWHERECity like '[aln]%--"Persons" table select people who live in cities that do not start with "A" or "L" or "N" select * from Persons' [! ALN]%'--The query is a name that begins with a three-word select * from tblstudent where tsname like'Single%'and LEN (tsname) =3
Reference: SQL wildcard characters
SQL basic operations-wildcard characters