SQL WildCards

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

Id Employee_Name Empl_Age
1 Sushil 22
2 Bhargav 32
3 Mohanthy 26
4 Mohan 38

 

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


SELECT * FROM Employee
WHEREmpl_AgeLIKE ‘2%’;


The result will be as

Id Employee_Name Empl_Age
1 Sushil 22
3 Mohanthy 26

 

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:

Id Employee_Name Empl_Age
3 Mohanthy 26
4 Mohan 38