Javatpoint Logo
Javatpoint Logo

LIKE Function in SQL

The Like(String) is a function in Structured Query Language which matches the pattern with the string. This function return 0 if the string is not matched with the pattern, otherwise 1. We can also use the Like function with the columns of the table.

Syntax of LIKE String Function

Syntax1: This syntax uses the LIKE function with two columns of the SQL table:

In the syntax, we have to define the name of that column whose values we want to match with the given pattern.

Syntax3: This syntax uses the LIKE function with two strings:

Examples of LIKE String function

Example 1: The following SELECT query compares the length of JAVATPOINT and EXAMPLES strings:



Example 2: The following SELECT query matches the string 'Javatpoint is good' with the given pattern:



Example 3: The following SELECT query compares the length of two cities:



Example 4: This example uses the LIKE function with the SQL table

In this example, we are going to create a new SQL table on which we have to execute the LIKE function for matching the column values with the pattern.

The syntax for creating the new table in the SQL database is as follows:

The following CREATE statement creates the Student_Grade table:

The below INSERT queries insert the recLIKEs of students with grades and marks in the Student_Grade table:

The following SELECT statement displays the inserted recLIKEs of the above Student_Grade table:

Roll_No First_Name Last_Name First_City Second_City New_City Hindi_Marks Maths_Marks Grade
10 Aman Sharma Lucknow Chandigarh Ghaziabad 88 95 A2
02 Vishal Sharma Chandigarh Ghaziabad Ghaziabad 95 82 A1
07 Raj Gupta Delhi Ghaziabad Lucknow 91 95 A1
04 Yash Singhania Ghaziabad Delhi Lucknow 85 82 A2
11 Vinay Roy Delhi Kanpur Ghaziabad 95 97 A1
16 Manoj Gupta Ghaziabad Meerut Chandigarh 95 90 B1
19 Ram Gupta Lucknow Ghaziabad Chandigarh 89 95 A2

The following SELECT query matches the Worker_First_Name column of the above table with the specified pattern:


Worker_First_Name Compare_Firstname_City
Arush 0
Bulbul 0
Saurabh 0
Shivani 0
Avinash 1
Shyam 0

The following SELECT query uses LIKE() with the Worker_first_Name and Worker_Last_Name columns of the above Worker_Info table:

This SQL statement matches the name of first name and last name columns.


Worker_First_Name Worker_Last_Name LIKE_Firstname_Lastname
Arush Sharma 0
Bulbul Roy 0
Saurabh Roy 0
Shivani Singhania 0
Avinash Sharma 0
Shyam Besas 0

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA