SQL LIKE Operator – SQL TUTORIAL | Software Testing Material

SQL LIKE Operator:

The SQL LIKE operator is used in a WHERE clause to compare a value to similar values using wildcard operators.

There are two wildcard operators used in conjunction with the Like operator.

Percentage sign ( % )

Underscore sign ( _ )

SQL LIKE Syntax:


Example – Like Operator:

In the below image, you could find two SELECT queries. First SELECT query returns the complete records of the table SCOREBOARD where as the second SELECT query returns the values only if the Playername is Sachin. We used WHERE clause in the second SELECT query with the LIKE operator.

SQL Like

Example – Like Operator with Wildcard %:

In the below image, you could find two SELECT queries. First SELECT query returns the complete records of the table SCOREBOARD where as the second SELECT query returns the values only if the Playername starts with letter D. We used WHERE clause in the second SELECT query with the LIKE operator and wildcard %.

SQL Like Operator With Wildcard

Example – Like Operator with Wildcard % At The Beginning:

In the below image, you could find two SELECT queries. First SELECT query returns the complete records of the table SCOREBOARD where as the second SELECT query returns the values only if the Playername consists the letter h. We used WHERE clause in the second SELECT query with the LIKE operator and wildcard before and after the letter h

SQL Like Operator With Wildcard At The Begining

Example – Like Operator with Wildcard _:

Example – Like Operator with Wildcard _ Before And After:

Example – Like Operator with Wildcard combination % and _:

NOT LIKE:

In the below image, you could find two SELECT queries. First SELECT query returns the complete records of the table SCOREBOARD where as the second SELECT query returns the values from the tables but it eliminates the values which has letter SacWe used WHERE clause in the second SELECT query with the NOT LIKE operator and the letters Sac with wild card % before and after the letters Sac.

SQL Not Like

In the next tutorial, we will see How To Use IN OPERATOR in SQL

Check out the complete SQL Tutorial by clicking on below link:

SQL Tutorial – Complete

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap