HOW TO USE LIKE OPERATOR IN SQL?

306 viewsSQLSQL
0

HOW TO USE LIKE OPERATOR IN SQL?

Saraswat World Changed status to publish June 8, 2023
0
LIKE in SQL
LIKE 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.

Saraswat World Changed status to publish June 8, 2023
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.

Posted

in

Tags:

Comments

Leave a Reply

Ganesh Ji Arti A Tribute to Dilip Kumar