SQL wildcard examples

SQL WILDCARDS are characters that are used with LIKE Operator
SQL WILDCARDS are used to search data within a table.
To learn about wildcards we need to know about the LIKE operator first.

 

SQL LIKE Operator

The LIKE operator is used to search for a particular pattern in a column.


The syntax of using LIKE operator is


SELECT column_name(s)
FROM table_name
WHEREcolumn_nameLIKE pattern;

 

Example:

Employee table

IdEmployee_NameEmpl_Age
1Sushil22
2Bhargav32
3Mohanthy26
4Mohan38

 

Using LIKE Operator or clause on the table to find required data:


SELECT * FROM Employee
WHEREmpl_AgeLIKE ‘2%’;


The result will be as

IdEmployee_NameEmpl_Age
1Sushil22
3Mohanthy26

 

Here in the example we have used Symbol “%” to match pattern. It is called as wildcard.


To match a number pattern we use ‘%’.
To match a character pattern we use ‘_’.


Let us take a another example to select the data based on character pattern


SELECT * FROM Employee
WHEREEmployee_NameLIKE ‘Mohan_’;


The result will be as follows:

IdEmployee_NameEmpl_Age
3Mohanthy26
4Mohan38