×

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 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.

SQL JOIN

As the name says, joins mean to merge something or to combine something. But in the case of SQL, joins mean to merge or combine two different tables. The Join clause...

12 minutes read.

How to drop a column in SQL?

How to drop a column in SQL Introduction To delete a column from an already created table, one needs to use the ALTER command along with the DROP COLUMN clause. Syntax: ALTER TABLE tablename...

4 minutes read.

SQL Insert multiple rows

This article will deal with a new insertion method in SQL which inserts multiple rows at a time. Multiple records can be inserted at a time into a specific table with...

4 minutes read.

SQL Handling Duplicate

Removing Duplicates using DISTINCT Keyword: By using the DISTINCT keyword in SQL we can remove duplicate characters from tables or databases. A table contains more duplicate values and duplicate values can cause...

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 SELECT Database

In this tutorial, we will help you to understand and learn how to select the database in SQL with the help of examples. The database user or the administrator wants to...

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.

SQL SET Operator

In this tutorial, we will understand the operator who falls under the SET operator in SQL with the help of different examples. The SQL SET Operator is used to merge the...

5 minutes read.

SQL Formatter

As a beginner, one does not focus much on Formatting the queries while writing their code. This leads to a great confusion while referring the code in future. For a...

5 minutes read.

Introduction to SQL

SQL Introduction SQL is Standard Query Language. This language is used to communicate or interact with database. In other words, SQL is used to access and manage data or information...

2 minutes read.

SQL SELECT AVG

In this tutorial, we will learn about the aggregate function name avg() function concept in SQL with the help of examples. The AVG() function is one of the aggregate functions in...

3 minutes read.

SQL WHERE Multiple Conditions

In this topic, we will learn how to add multiple conditions using the WHERE clause. First, let's understand the concept of WHERE clause. WHERE clause is used to specify a condition while...

5 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.

Commit and Rollback in SQL

In Structured Query Language, we have Data Definition Language (DDL) and Data Manipulation Language (DML) commands the same way we have Transaction Control Language (TCL) commands in the Structured Query...

4 minutes read.

SQL SELECT IN

SQL SELECT IN is a logical operator in Structured Query Language. It is used in SQL queries to reduce the use of multiple 'OR' operators. s The IN operator in SQL...

6 minutes read.

SQL Aggregate Functions

In this tutorial, we will learn and understand the SQL Aggregate Functions concept with the help of examples. SQL Aggregate Function is a function used to perform calculation operations on one...

4 minutes read.

How to use COUNT in SQL?

How to use COUNT in SQL Introduction COUNT( ) is an aggregate function in SQL.This function counts the number of records in a table if the condition is not specified.If the condition...

4 minutes read.

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.

WHERE Clause vs HAVING Clause

The WHERE Clause and HAVING clause filter the records in the Structured Query Language queries. The main difference between the WHERE clause and the HAVING clause is the WHERE clause...

5 minutes read.