EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials SQL Tutorial LIKE Query in SQL
 

LIKE Query in SQL

Roja Metla
Article byRoja Metla
EDUCBA
Reviewed byRavi Rathore

Updated March 24, 2023

LIKE Query in SQL

 

 

Introduction to LIKE Query in SQL

LIKE query is used to search for a particular pattern from the table rows and return the columns, which matches the pattern. When you only know a fragment of a text value and need to get the details from the table. Then you can get the values that match the pattern mentioned by using the “LIKE” query in SQL.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

LIKE query has a two-wildcard match.

They are mentioned below:

  • “%”: Matches any string with zero or more characters.
  • “_”: Matches any single character.

Syntax for LIKE Query in SQL:

In this section let us discuss the significance of the “LIKE” and its syntax.

SELECT Col_name1, col_name2, .. , col_nameN
FROM <Table_name>
WHERE <Col_name1> LIKE <value>

How to Use LIKE Query in SQL?

Let us take an example and see how the LIKE query works in the SQL.

Let us consider the below LOAN_034 table:

Creating LOAN_034 Table:

Code:

CREATE TABLE LOAN_034(
LOAN_NO VARCHAR(25) PRIMARY KEY,
NAME VARCHAR(25),
AMOUNT INTEGER(10),
AP_DATE DATE
);

Inserting Data into the LOAN_034 Table:

Code:

INSERT INTO LOAN_034 VALUES ("3A34","Ram", 89000, "2018-06-12");
INSERT INTO LOAN_034 VALUES ("4E25","Ravi", 25000, "2015-06-25");
INSERT INTO LOAN_034 VALUES ("1R12","Santosh", 69000, "2017-01-23");
INSERT INTO LOAN_034 VALUES ("53RT","Samuel", 39560,"2015-05-04");
INSERT INTO LOAN_034 VALUES ("2RR3","Kartika", 88756,"2019-05-26");
INSERT INTO LOAN_034 VALUES ("8PP9","Donald", 22568, "2009-05-13");
INSERT INTO LOAN_034 VALUES ("0PK9","Donald Parker", 35684, "2006-03-18");
INSERT INTO LOAN_034 VALUES ("7JI8","Danny", 90000, "2013-04-27");
INSERT INTO LOAN_034 VALUES ("OWE3","Harsh", 64988,"2019-08-15");
INSERT INTO LOAN_034 VALUES ("PPL1","Blue park", 27568, "2019-04-19");
INSERT INTO LOAN_034 VALUES ("R34E","chai", 56000, "2019-08-15");
INSERT INTO LOAN_034 VALUES ("WE45","Chang",79000, "2019-04-19");
select * from LOAN_034;

Output:

Loan Table

Example #1

Get all the details of the people whose name’s start with “R” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE 'R%';

Output:

Selected Names

Example #2

Get all the details of the people whose name’s start with “don” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE 'DON%';

Output:

Upper Names

Example #3

Get all the details of the people whose name’s start with “cha” and “chan” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE UPPER ('CHA_') OR UPPER (NAME) LIKE UPPER ('CHAN_');

Output:

Like Query in SQL 1-4

Example #4

Get all the details of the people whose name contains “park” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE '%PARK%';

Output:

Like Query in SQL 1-5

Example #5

Get all details of the people whose names contain LETTER “M” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE '%M%';

Output:

Like Query in SQL 1-6

Example #6

Get all the details of the people whose name contains “Donald” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE '%DONALD%';

Output:

Like Query in SQL 1-7

Example #7

Get all details of the people whose name STARTS WITH “A”, STARTS WITH “K”, and ENDS WITH “A” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE ‘A%’ OR UPPER (NAME) LIKE ‘K%’
OR UPPER (NAME) LIKE '%A';

Output:

Like Query in SQL 1-8

Example #8

Get all details of the people whose NAME STARTS WITH “H” and ENDS WITH “H” from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE 'H%H';

Output:

Like Query in SQL 1-9

Example #9

Get all details of the people whose NAME STARTS WITH “R” and ENDS WITH “M” and has only one letter in between them from the above table.

Code:

SELECT * FROM LOAN_034
WHERE UPPER (NAME) LIKE 'R_M';

Output:

Like Query in SQL 1-10

Recommended Articles

This is a guide to LIKE Query in SQL. Here we discuss the introduction and how to use LIKE queries in SQL along with a few examples and implementation of queries. You may also look at the following articles to learn more –

  1. How ORDER BY Clause Work in MySQL?
  2. Examples of Composite Key in SQL
  3. Working of AND in SQL with Examples
  4. Top 7 SQL Keys with Examples

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW