×

SQL SELECT LIKE Operator

The SQL SELECT LIKE Operator tutorial helps us understand how to use the LIKE operator in the SELECT query with examples.

The SQL SELECT LIKE Operator retrieves the records from the table, which finds the data using wildcard options. The SQL LIKE operator is used with the WHERE clause in the query.

Following are the two wildcard characters are used to find the pattern matching string from the table.

1 Percent Wildcard Character (%)

2 Underscore Wildcard Character (_)

The syntax of the LIKE Operator with the SELECT statement is as follows:

SELECT Column_1, Column_2, Column_3. Column_4, Column_5 FROM Table_Name WHERE Column_Name LIKE expression;

1 Percent Wildcard Character (%): The Percent Wildcard Character symbol is used to search the zero, one, or more than one string character.

The syntax of the SQL SELECT LIKE operator using Percent wildcard Character is as follows:

SELECT Column_1, Column_2, Column_3. Column_4, Column_5 FROM Table_Name WHERE Column_Name LIKE %expression%;

2 Underscore Wildcard Character (%): The Underscore Wildcard Character symbol searches for the zero or one string character.

The syntax of the SQL SELECT LIKE operator using Underscore wildcard Character is as follows:

SELECT Column_1, Column_2, Column_3. Column_4, Column_5 FROM Table_Name WHERE Column_Name LIKE ___%;

We can use the AND operator and the OR operator for multiple combinations in the query.

Let’s understand the SQL SELECT LIKE operator with the help of an examples

Consider the already existing table with the certain records

Table Number 1: Student

Student_IdStudent_NameCityAge
1Pratik SrivastavPune23
2Utkarsh RokadeMumbai22
3Sourabh ChougaleNashik23
4Prateek ZimbrePune24
5Sakshi PatilAurangabad22
6Shruti SharmaMumbai21
7Pranoti ShendeAurangabad23
8Harshada DhanwatNashik24
9Tejas BairagiNashik21
10Nikhil PatilPune24
11Samaira SharmaMumbai22
12Anushka SenAurangabad23
13Bhushan PachpandeBangalore25
14John ChaudharyBangalore24
15Sonakashi SenBangalore25
16Mayuri WaghHyderabad22
17Ritika PatilHyderabad21
18Tushar MahaleHyderabad23

Table Number 2: Course

Course_IdCourse_NameStudent_IdDuration
11Cloud Computing23
12SQL Database11
13Advance Java43
14Data Structures76
15AWS82
16Angular Js103
17Oracle Integration Cloud116
18Python61
19ReactJs13
20Computing64

Example 1: Execute a query to display the student information from the student table where the student name starts with the 'S' letter.

SELECT * FROM Student WHERE Student_Name LIKE 'S%';

The above SELECT LIKE operator query example retrieved all the student information from the student table where the student name starts with the letter 'A'.

The output of the above query is as follows:

Student_IdStudent_NameCityAge
3Sourabh ChougaleNashik23
5Sakshi PatilAurangabad22
6Shruti SharmaMumbai21
11Samaira SharmaMumbai22
15Sonakashi SenBangalore25
SQL SELECT LIKE Operator

Example 2: Execute a query to display the student information from the student table where the student name ends with the 'E’ letter.

SELECT * FROM Student WHERE Student_Name LIKE '%E';

The above SELECT LIKE operator query example retrieved all the student information from the student table where the student name ends with the letter 'E'.

The output of the above query is as follows:

Student_IdStudent_NameCityAge
2Utkarsh RokadeMumbai22
3Sourabh ChougaleNashik23
4Prateek ZimbrePune24
7Pranoti ShendeAurangabad23
13Bhushan PachpandeBangalore25
18Tushar MahaleHyderabad23
SQL SELECT LIKE Operator

Example 3: Execute a query to display the student information from the student table where the student name contains the letter 'T' at any position.

SELECT * FROM Student WHERE Student_Name LIKE '%T%';

The above SELECT LIKE operator query example retrieved all the student information from the student table where the student name contains the letter 'T' anywhere.

The output of the above query is as follows:

Student_IdStudent_NameCityAge
1Pratik SrivastavPune23
2Utkarsh RokadeMumbai22
4Prateek ZimbrePune24
5Sakshi PatilAurangabad22
6Shruti SharmaMumbai21
7Pranoti ShendeAurangabad23
8Harshada DhanwatNashik24
9Tejas BairagiNashik21
10Nikhil PatilPune24
17Ritika PatilHyderabad21
18Tushar MahaleHyderabad23
SQL SELECT LIKE Operator

Example 4: Execute a query to display the course information from the course table where the course name starts with 'A' and ends with  'S'.

SELECT * FROM Course WHERE Course_Name LIKE 'A%S';

The above SELECT LIKE operator query example retrieved all the student course information from the course table where the course name starts with the letter 'A' and ends with the letter 'S'.

The output of the above query is as follows:

Course_IdCourse_NameStudent_IdDuration
15AWS82
16Angular Js103
SQL SELECT LIKE Operator

Example 5: Write a query to display the student information from the student table whose student city contains U at the second position.

SELECT * FROM Student WHERE City LIKE '_U%';

The above SELECT LIKE operator query example retrieved all the student course information from the course table where the city name contains the letter 'U' at the second index.

The output of the above query is as follows:

Student_IdStudent_NameCity
1Pratik SrivastavPune
2Utkarsh RokadeMumbai
4Prateek ZimbrePune
5Sakshi PatilAurangabad
6Shruti SharmaMumbai
7Pranoti ShendeAurangabad
10Nikhil PatilPune
11Samaira SharmaMumbai
12Anushka SenAurangabad
SQL SELECT LIKE Operator

Example 6: Write a query to display the student information from the student table whose student city name is 6 letters.

SELECT * FROM Student WHERE City LIKE '______';

The above SELECT LIKE operator query example retrieved all the student course information from the student table. The city name contains only 6 letters, starts with any letter, and ends with any letter.

The output of the above query is as follows:

Student_IdStudent_NameCityAge
2Utkarsh RokadeMumbai22
3Sourabh ChougaleNashik23
6Shruti SharmaMumbai21
8Harshada DhanwatNashik24
9Tejas BairagiNashik21
11Samaira SharmaMumbai22
SQL SELECT LIKE Operator

Related Topics

How to Add Comments in SQL?

How to Add Comments in SQL Comments are text notes that are incorporated into the program to make the code easier to understand. In SQL, commenting is used to explain various sections...

2 minutes read.

What is SQL Injection?

Introduction to SQL Injection SQL injection is a vulnerability or a technique that might destroy the database of a website or a web application. It is one of the most widely...

4 minutes read.

SQL INSERT INTO Values

This article will help you in getting a better understanding of a very important SQL INSERT INTO VALUES function. INSERT INTO statement is used to insert or add a new record...

4 minutes read.

SQL LOGICAL Operator

In this tutorial, we will understand the operator who falls under the logical operator in SQL with the help of examples. The SQL Logical Operator displays the query result in one...

5 minutes read.

SQL KEYS

SQL KEYS are single or multiple attributes used to get data from the table according to the requirement or condition. They can also be used to set up relationships amongst...

3 minutes read.

How to remove duplicates in SQL

Introduction There are some specific rules that needs to be followed while creating the database objects. To improve the performance of a database, a primary key, clustered and non-clustered indexes, and...

9 minutes read.

How to Update Table in SQL?

How to Update Table in SQL Introduction UPDATE query is used to update a record in a table. UPDATE is a DML command, which operates on the data of the table and not...

4 minutes read.

SQL Primary Key

A field, which contains unique data in a table, is called a PRIMARY KEY (PK). It means, a PRIMARY KEY field must contain unique data in the table. A PRIMARY KEY...

4 minutes read.

SQL WHERE Statement

SQL WHERE Statement Introduction WHERE clause is used to include a condition while fetching data from tables.When you have to specify a condition that has to be obeyed while data is...

9 minutes read.

SQL Wildcards

SQL WILDCARD CHARACTERS: SQL wild card character is used to substitute zero or more characters of a string. These characters are used with the “LIKE” operator. Wild Card Characters in SQL: %_[]^- “%” : It is...

3 minutes read.

How to use INNER JOIN in SQL

In this article, we will learn about the INNER JOIN concept and how to use it in SQL with the WHERE clause. What is INNER JOIN in SQL? Inner Join is a...

6 minutes read.

SQL Temporary Tables

Temporary Table: The Temporary tables are generally created in TempDB. If the last connection is terminated then the tables are deleted automatically. These are generally used to store and process the...

4 minutes read.

SQL Inner Join

In Structured Query Language, the most used join query is the Inner join query. Inner join query retrieves the records from one or more tables with similar data or records. The...

4 minutes read.

SQL SELECT OR Operator

This SQL tutorial explains and helps us understand how to use the OR operator in the SELECT query with examples. The OR operator in the Structured Query Language is used to...

3 minutes read.

SQL CRUD Operation

In any computer language, CRUD operation is a foundation. CRUD operation rules are applied in databases as well. These operations are the basic operations used to perform with any database...

7 minutes read.

SQL UPDATE

SQL UPDATE The SQL UPDATE statement is utilized to update and modify the records present into a database. It is used to change the already existing records stored in the tables...

3 minutes read.

SET Operators in SQL

The operator used to join or combine two queries is none other than SET operators. Operators categorized into SET operators are as follows: UNION Operator.UNION ALL’ Operator.INTERSECT Operator.MINUS Operator. Rules to be...

8 minutes read.

SQL SELECT AND Operator

This SQL tutorial explains and helps us understand how to use the AND Operator in the SELECT query with examples. The AND Operator is used to fetch the table’s records if...

2 minutes read.

SQL SET Keyword

This article will provide you a good understanding of the Set keyword in Structured Query Language. What is the SET keyword? The SET keyword is used to specify values for the variables....

3 minutes read.

Where vs Having

Difference Between Where and Having The WHERE and HAVING clauses in SQL are used to filter records stored in tables in the databases. The dissimilarities between the WHERE and HAVING clause...

3 minutes read.