LIKE operator is used in a WHERE clause to search for a specified pattern in a column. SQL LIKE Operator uses following two wildcard characters in conjuction or independently-
1.% (Percent Sign)- It matches zero, one or more than one characters.
2._ (Underscore Sign)โ It matches only one or a single character.
Syntax โ
SELECT(ColumnName(s)) FROM <TableName> WHERE<ColumnName>LIKE <pattern> ;
Examples-
SELECT * FROM Customers WHERE CustomerName LIKE โc%โ;
โIt will select all the customer name starting with โcโ.
SELECT * FROM Customers WHERE CustomerName LIKE โ_c%โ;
โIt will select all the customer name having second character โcโ.
SELECT * FROM Customers WHERE CustomerName LIKE โD%hโ;
โIt will select all the customer name starting with โDโ and ending with โhโ.
Note-
Northwind sample database is used for example.
Leave a Reply