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.