LIKE Function in SQLThe 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 FunctionSyntax1: 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 functionExample 1: The following SELECT query compares the length of JAVATPOINT and EXAMPLES strings: Output: 0 Example 2: The following SELECT query matches the string 'Javatpoint is good' with the given pattern: Output: 1 Example 3: The following SELECT query compares the length of two cities: Output: 0 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:
The following SELECT query matches the Worker_First_Name column of the above table with the specified pattern: Output:
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. Output:
Next TopicORD Function in SQL |