The SQL LIKE Operator
The LIKE operator is used to search for a specified pattern in a column.SQL LIKE Syntax:
SELECT column_name(s)FROM table_name
WHERE column_name LIKE pattern;
Examples
SELECT * FROM tbsample WHERE EmployeeName LIKE 's%' -- selects all from tbsample with a EmployeeName Starting with the letter "s"
SELECT * FROM tbsample WHERE EmployeeName LIKE '%m' -- selects all from tbsample with a EmployeeName ending with the letter "m"
SELECT * FROM tbsample WHERE EmployeeName LIKE '_a%' -- selects all from tbsample with a EmployeeName Starting with any letter and the next letter must be "a" followed by any letters.
SELECT * FROM tbsample WHERE EmployeeName LIKE '[a-k]%' -- selects all from tbsample with a EmployeeName Starting from "a" to "k" followed by any letters.
SELECT * FROM tbsample WHERE EmployeeName LIKE '_[a-k]%' -- selects all from tbsample with a EmployeeName Starting from any letter ,next letter should be between "a" to "k" followed by any letters.
SELECT * FROM tbsample WHERE EmployeeName LIKE '[^a-k]%' -- selects all from tbsample excluding ( EmployeeName Starting from "a" to "k" ) followed by any letters.
SELECT * FROM tbsample WHERE EmployeeName LIKE '_[^a-k]%' -- selects all from tbsample with a EmployeeName Starting from any letter ,next letter should exclude ( EmployeeName Starting from "a" to "k" ) followed by any letters.
No comments:
Post a Comment