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