SQL Like operator

      No Comments on SQL Like operator

SQL Like operator matches the string with specific strings in a record to return the value where there is a match. LIKE operator checks that the string specified matched with string in a record or contains some part or pattern of it.

SQL Like operator

SQL Like is used to search a specific pattern in a column.

Syntax:

SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;

Demo Database:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd

SQL Like examples:

The following SQL statement searches the with name starting with ‘s’ in the column name C.name

SELECT * FROM Customers
WHERE C.name LIKE 's%'; 

Result:

C.idC.nameC.contactC.address
00146hhSia812300912#212,sec-86 panchukula

The following SQL statement searches the with name ending with ‘h’ in the column name C.name

SELECT * FROM Customers
WHERE C.name LIKE '%h'; 

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali

The following SQL statement searches the with name containing the pattern ‘Ra’ in the column name C.name

SELECT * FROM Customers
WHERE C.name LIKE '%Ra%'; 

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
144dcv4Rahul700912366#001,sec-19 c chd

NOT LIKE

The following SQL statement searches the with name NOT containing the pattern ‘Ra’ in the column name C.name

SELECT * FROM Customers
WHERE C.name NOT LIKE '%Ra%'; 

Result:

C.idC.nameC.contactC.address
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula

Leave a Reply

Your email address will not be published. Required fields are marked *