Wildcards in SQL

Sql, Wildcard

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

There are two wild card characters in SQL. One is underscore ‘_’ and other is percentage ‘%’.

If you know exact string ane missing one of the character in string you may use underscore in select query.

e.g. You are looking for word that starts with ‘tes’ and is four characters in length , you may use below query.

SELECT * FROM tablename WHERE columnname like ‘tes_’

e.g. You don not know exact length of string, you may use % character.

SELECT * FROM tablename WHERE columnname like ‘tes%’

In both cases you can use these wildcard characters at any position in string i.e. Between the string characters or at the beginning or at the end.