SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL Data Types SQL OPERATORS SQL COMMANDS SQL Queries

SQL Database

SQL Create Database SQL DROP Database SQL SELECT Database

SQL Table

SQL TABLE SQL CREATE TABLE SQL COPY TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL DROP TABLE SQL UPDATE TABLE SQL INSERT TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT WHERE Clause SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT OR Operator SQL SELECT LIKE Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL WHERE Clause SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT Statement SQL INSERT INTO Statement SQL INSERT INTO Values SQL INSERT INTO SELECT SQL Insert multiple rows

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL CROSS Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Cast Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS Difference between Delete, Drop and Truncate in SQL

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL Aggregate Operators SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL SQL Formatter WEB SQL SQL Auto Increment Save Point in SQL space() function in SQL SQL Aggregate Functions SQL Topological Sorting SQL Injection SQL Cloning Tables SQL Aliases SQL Handling Duplicate Update Query in SQL Grant Command in SQL SQL SET Keyword SQL Order BY LIMIT SQL Order BY RANDOM

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL How index works in SQL How to calculate age from Date of Birth in SQL How to Rename Column name in SQL What are single row and multiple row subqueries?

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