LIKE in SQL

HOW TO USE LIKE OPERATOR IN SQL?


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.


Posted

in

Tags:

Comments

Leave a Reply