Skip to content
Facebook-f Twitter Instagram Pinterest
  • HOME
  • INSIGHTS
    • BLOG
    • ARTICLES
  • TUTORIALS
    • PYTHON
      • PYTHON MODULES
        • NUMPY
        • PANDAS
        • SCIPY
    • MATPLOTLIB
    • MACHINE LEARNING
    • PYTHON MYSQL
    • SQL
      • SQL DATABASE
      • SQL THEORY
    • JAVA
      • JAVA THEORY
    • GRAPH THEORY And COMBINATORICS
  • PROJECTS
    • PYTHON PROJECT
    • JAVA PROJECT
  • ABOUT
  • CONTACT US
Menu
  • HOME
  • INSIGHTS
    • BLOG
    • ARTICLES
  • TUTORIALS
    • PYTHON
      • PYTHON MODULES
        • NUMPY
        • PANDAS
        • SCIPY
    • MATPLOTLIB
    • MACHINE LEARNING
    • PYTHON MYSQL
    • SQL
      • SQL DATABASE
      • SQL THEORY
    • JAVA
      • JAVA THEORY
    • GRAPH THEORY And COMBINATORICS
  • PROJECTS
    • PYTHON PROJECT
    • JAVA PROJECT
  • ABOUT
  • CONTACT US
Search
Close
sql-like-operator

Get Started: SQL LIKE Operator

  • March 29, 2022
In This Article, You Will Know About SQL LIKE Operator. 

SQL Functions – Before moving ahead, let’s know a bit about SQL MIN() and MAX() Functions.

Table of Contents

SQL LIKE operator

The SQL LIKE operator is used with the WHERE clause to find out the specified pattern in the column.

Two most popular wildcards are used with the LIKE operator:

(%) – The percentage (%) sign is used to match zero, one, or multiple characters.

(_) – The underscore sign is used to represent one or a single character.

Syntax

				
					SELECT column1, column2, ...
FROM table_name
WHERE column LIKE pattern;
				
			

Here are some examples showing different LIKE operators with ‘%’ and ‘_’ wildcards:

LIKE Operator

Description

WHERE CustomerName LIKE ‘A%’

Finds any values that start with “A”

WHERE CustomerName LIKE ‘%x’

Finds any values that end with “x”

WHERE CustomerName LIKE ‘%e%’

Finds any values that have “e” in any position

WHERE CustomerName LIKE ‘_l%

Finds any values that have “_l” in the second position

WHERE CustomerName LIKE ‘R____%’     

Finds any values that start with “R” and are at least 5 characters in length

WHERE ContactName LIKE ‘A%x’

Finds any values that start with “A” and ends with “x”

Example Database

Below is the example of a database table named “details.”

Id

Name

Class

section_id

1

Alex

5

1

2

Rolex

6

2

3

Salex

7

2

4

Lelex

8

3

5

Kelex

9

5

SQL LIKE Examples

Example: Use LIKE operator to return the match starts with ‘A’.

				
					SELECT * FROM details
WHERE Name LIKE 'A%';
				
			

As a result, it returns the all names starts with “A” from the whole table.

Example: Use LIKE operator to return the match starts with ‘S’.

				
					SELECT Name 
FROM details
WHERE Name LIKE 'S%';
				
			

As a result, it returns the all names starts with “S” from the “Name” column.

Example: Use LIKE operator to return the match ends with ‘x’.

				
					SELECT Name 
FROM details
WHERE Name LIKE '%x';
				
			

As a result, it returns the all names ends with “x” from the “Name” column.

Example: Use LIKE operator to return the match have ‘e’ character at any position.

				
					SELECT Name 
FROM details
WHERE Name LIKE '%e%';
				
			

As a result, it returns the all names that contains “e” at any position from the “Name” column.

Example: Use LIKE operator to return the match have ‘l’ character in the second position.

				
					SELECT * FROM details
WHERE Name LIKE '_l%';
				
			

As a result, it returns the all names that contains second character “l” from the whole table.

Example: Use LIKE operator to return the match have ‘R’ character in the first position.

				
					SELECT * FROM details
WHERE Name LIKE 'R____%';
				
			

As a result, it returns the all names from the whole table that starts with character “R” and have at least total 5 characters in the length.

Example: Use LIKE operator to return the match have ‘R’ character in the first position, ‘l’ at any position, and ‘x’ at the last position.

				
					SELECT * FROM details
WHERE Name LIKE 'R__l__x%';
				
			

As a result, it returns the all names from the whole table that starts with character “R” and have at least total 5 characters in the length.

Example: Use LIKE operator to return the match have ‘A%x’ character “A” in the starting and “x” at the last.

				
					SELECT * FROM details
WHERE Name LIKE 'A%x';
				
			

As a result, it returns the all names from the whole table that starts with character “A” and end with character “x”.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Facebook Instagram Twitter Pinterest
PrevPreviousSQL Functions : COUNT(), AVG() and SUM()
NextGet Started: SQL WildcardNext

Recent Post

Introduction to Access Specifier in Java
Read More »
Introduction to Object-Oriented Programming
Read More »
Introduction To Functional Dependency
Read More »
Introduction to Dijkstra Algorithm
Read More »
Get started: Introduction to Java Switch Case
Read More »

Popular Post

Get Started: SQL CASE Statement
Read More »
Creation of Own Numpy Universal Function in Python
Read More »
Top Python Libraries for Data Science in 2022
Read More »
Get Started: SQL MIN() and MAX() Functions
Read More »
Introduction to Machine Learning Train/Test
Read More »

Top Articles

Top 8 Reasons Why You Should Think of Python in 2022
Read More »
The Starting Of An Era: Top Programming Languages Will Be In Demand In 2022
Read More »
Ten Back-end Programming Languages In 2022
Read More »
Old Code: Outdated Programming Languages In 2022
Read More »
Top Reasons to Learn Java
Read More »
Archives
Categories
Tags
array in python Article Articles Articles 2021 codingstreets codingstreets tutorial 2022 java java language java language 2022 python python article python article 2022 Python Articles Python Articles 2022 python introduction python language python matplotlib python matplotlib tutorial 2021 Python MySQL Python mysql 2022 python numpy python numpy array Python Numpy Tutorial python numpy tutorial 2021 python numpy tutorial august 2021 python numpy tutorial sept 2021 python pandas concept Oct 2021 python pandas Tutorial Oct 2021 python pandas tutorial Sept 2021 python program python programming language article 2022 Python SQL Python SQL 2022 python string Python String Method Python String Method 2021 Python String Method tutorial 2022 python tutorial python tutorial sept 2021 SQL Theory start with python string concept string introduction string methods string python

Share on

Subscribe to our newsletter

Just a step behind to get all updates
Don’t miss new updates on your mail


Loading

Useful Links

  • FEEDBACK
  • SITEMAP
  • HELP

Get Started

  • PYTHON TUTORIAL
  • PROJECTS
  • QUIZ

About

  • TERM & CONDITIONS
  • PRIVACY & POLICY
  • DISCLAIMER
Facebook Twitter Instagram Pinterest

Copyright © 2023 codingstreets.com - All Rights Reserved