In SQL, Operators are special character, symbol or a keyword that is used to perform some specific operations. For example : comparing data
SQL operators are commonly used with SQL statements to retrieve, filter, and manipulate data.
LIKE operator act as a search engine that searches for the specified pattern or substring in a column. It is used in 'WHERE' clause to filter and retrieve specific data.
• Pattern refers to a sequence of characters in SQL. It can be a single or multiple character.
SELECT column_name(s) FROM table_name WHERE column LIKE pattern;
• Specify the column(s) name after the 'SELECT' keyword.
• Specify Asterisk (*) symbol to selects all columns from the table after the 'SELECT' keyword.
• Specify the table name after the 'FROM' keyword.
• Specify the conditions after the 'WHERE' keyword.
• Specify the pattern after the 'LIKE' keyword.
1. Let's assume we have a table named "[Employees]".
Let's assume you want to retrieve employee data from [Employees] table where Employee_Name starts with character 'A'.
Run below SQL statement :
SELECT * FROM [Employees] WHERE Employee_Name LIKE 'A%';
Above statement will retrieve employee data where Employee_Name starts with character 'A'.
Let's assume you want to retrieve employee data from [Employees] table where Employee_Name ends with character 'Y'.
Run below SQL statement :
SELECT * FROM [Employees] WHERE Employee_Name LIKE '%Y';
Above statement will retrieve employee data where Employee_Name ends with character 'Y'.
Let's assume you want to retrieve employee data from [Employees] table where Employee_Name has character 'OL' as the second and third character.
Run below SQL statement :
SELECT * FROM [Employees] WHERE Employee_Name LIKE '_OL%';
Above statement will retrieve employee data where Employee_Name has character 'OL' as the second and third character.
Let's assume you want to retrieve employee data from [Employees] table where Employee_Name has character 'A' anywhere.
Run below SQL statement :
SELECT * FROM [Employees] WHERE Employee_Name LIKE '%A%';
Above statement will retrieve employee data where Employee_Name has character 'A' anywhere.
The LIKE operator in SQL is used for pattern matching within strings.
No, the LIKE and IN operators cannot be used together in SQL.
The AS operator in SQL is used to alias columns or tables.
ILIKE is used in some SQL databases (like PostgreSQL) for case-insensitive pattern matching, whereas LIKE is case-sensitive.