Wednesday, 14 February 2018

How to use SQL LIKE operator different way in SQL Query

LIKE operator use in WHERE condition that search pattern wise in column

LIKE operator use 2 wildcard

1. % percent sign use for more than 1 characters

2. _ underscore use for single characters

LIKE Syntax

SELECT ColumnName FROM YourTableName WHERE ColumnName LIKE YourCondition

Example

1. SELECT TOP 1 * FROM Client WHERE LastName LIKE 'A%'
- filter records start with A character

2. SELECT TOP 1 * FROM Client WHERE LastName LIKE '%A'
- filter records end with A character

3. SELECT TOP 1 * FROM Client WHERE LastName LIKE '%A%'
- filter records anywhere get char A in field

4. SELECT TOP 1 * FROM Client WHERE LastName LIKE '_A%'
- filter records that contains second char A

5. SELECT TOP 1 * FROM Client WHERE LastName LIKE 'A%S'
- filter records that first char A and last char is S

No comments:

Post a Comment