SQL โ Like
SQL Like Clause
Like operator is used to filter the results . Like operator compares the results using the wild cards.
There are two types of wildcards used for the filtering & matching the result.
1. % โ (Percent Symbol).
2. _ โ (Underscore Symbol).
SQL Like CLause Syntax (Wildcard %)
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โ%Patternโ;
Or
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โPattern%โ;
or
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โ%Pattern%โ;
Explanation :
โPattern%โ โ : Mathes & finds the pattern where column value starts with the provided pattern (Ex . โ โ%Johnโ โ Will find the records where Name(Column) starts with โJohnโ).
โ%Patternโ โ : Mathes & finds the pattern where column value ends with the provided pattern (Ex . โ โJohn%โ โ Will find the records where Name(Column) ends with โJohnโ ).
โ%Pattern%โ โ : Mathes & finds the pattern where pattern find at any place in column value (Ex . โ โ%John%โ โ Will find the records where Name(Column) find at any where ).
SQL Like CLause Syntax (Wildcard _ ) โ
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โ_Patternโ;
Or
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โPattern_โ;
or
SELECT columnName1, ColumnName2.. FROM TableName WHERE ColumnName LIKE โ_Pattern_โ;
Explanation :
โ_Patternโ โ : Mathes & finds the pattern where column value has the pattern at second place (Ex . โ โ_Jโ โ Will match the column value where second value is โJโ).
โPattern_โ โ : Mathes & finds the pattern where column value start with the pattern (Ex . โ โJ%โ โ Will match the column value where column value starts with โJโ ).
โ_Pattern_โ โ : Mathes & finds the pattern where pattern where (Ex . โ โ_Jn_โ โ Will find the records where 2nd value is โJโ and seond last value is โnโ ).
Example :
Example
Will Produce The Follwoing Result.
Example :
Example
Will Produce The Follwoing Result.
Advertisements