Back-End Development SQL basics

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:

Demo Database:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #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

Result:

C.id C.name C.contact C.address
00146hh Sia 812300912 #212,sec-86 panchukula

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

Result:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali

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

Result:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
144dcv4 Rahul 700912366 #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

Result:

C.id C.name C.contact C.address
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula