alternative
  • Home (current)
  • About
  • Tutorial
    Technologies
    SQL -Structured Query Language
    Python
    Ethical Hacking
    Java
    .net Framework
    Placement Preparation
    Quantitative Aptitude
    View All Tutorial
  • Quiz
    SQL -Structured Query Language
    Quantitative Aptitude
    Java
    View All Quiz Course
  • Q & A
    Quantitative Aptitude
    Java
    View All Q & A course
  • Programs
  • Articles
    Artificial Intelligence & Machine Learning Project
    How to publish your local website on github pages with a custom domain name?
    How to download and install Xampp on Window Operating System ?
    How To Download And Install MySql Workbench
    How to install Pycharm ?
    How to install Python ?
    How to download and install Visual Studio IDE taking an example of C# (C Sharp)
    View All Post
  • Tools
    Program Compiler
    Sql Compiler
    Replace Multiple Text
    Meta Data From Multiple Url
  • Contact
  • User
    Login
    Register

SQL -Structured Query Language - Sql Clause - Like Clause Tutorial

To retrieve a record having a specific pattern in a record from the existing created table. Then we can use a ' WHERE ' Clause with LIKE Operator.

There are two wildcard operator used with like clause to find a similar pattern in the record-

  1. % - The percent sign is used when we don’t know how many characters are below and above of specific character.

 Suppose in a table

name

~ Sharad

~ Saurabh

Shantanu

~ Param

Vaibhav

 

We have to retrieve names having specific character “ra”, hence we don’t know how many characters are below and above of specific character “ra”.

Therefore here we used the LIKE “%ra%” Statement.

This will retrieve “Sharad”, “Saurabh” and “Param”. Because this name is matching the given-like condition.

 

Syntax-

SELECT * FROM table_name WHERE column_name LIKE ‘%specific_character%’;

 

For example-

SELECT * FROM employees WHERE first_name LIKE '%ra%';

Run Query

In this statement, it will retrieve the first_name having specific syntax “ra” in it from the table employees.

 

  1. _ - The underscore sign is used when we know how many characters are below and above of specific character.

 Suppose in a table

name

Sharad

Saurabh

Shantanu

Param

~ Vaibhav

 

We have to retrieve a name having a specific character “aib”, And there should be only one character below and three characters above the specific character “aib”.

Therefore here we used the LIKE “_ aib_ _ _” Statement.

This will retrieve the name “Vaibhav”. Because “Vaibhav” matches the given like condition.

 

Syntax-

SELECT * FROM table_name WHERE column_name LIKE ‘_specific_character_ ’;

 

For example-

SELECT * FROM employees WHERE first_name LIKE '_ar__';

Run Query

In this statement, it will retrieve the first_name having specific syntax “ar” in it with one character below it and two-character above it, from the table employees.

 

Other examples-

SELECT * FROM employees WHERE first_name LIKE '_ar%';

SELECT * FROM employees WHERE first_name LIKE '%a_r%';

Run Query

Table for more clarification on LIKE Clause

 

Sr.no

Different format LIKE Clause is used

Explanation

1

LIKE ‘ab%’

It will retrieve the value that starts with “ab” and end with any number of any character

2

LIKE ‘%ab%’

It will retrieve the value that having “ab” in between it

3

LIKE ‘%ab’

It will retrieve the value that ends with “ab” and start with any number of any character

4

LIKE ‘_ab’

It will retrieve the value that ends with “ab” and having only one character below “ab”.

5

LIKE ‘_ab_ _’

It will retrieve the value that starts with one character below and end with two characters above the “ab”.

6

LIKE ‘%ab_’

It will retrieve the value that ends with one character above “ab” and start with any number of the character below “ab”.

7

LIKE ‘%a_b%’

It will retrieve the value that having one character between “a” and “b”, start and end with any number of characters below and above “a_b”.

 

SQL -Structured Query Language

SQL -Structured Query Language

  • Introduction
  • Overview
    • How To Download And Install MySql Workbench
    • SQL Syntax
  • SQL Database
    • Create Database
    • Drop Database
    • Use / Select Database
  • SQL Table
    • Create Table
    • Alter - Rename Table
    • Alter - Add Column
    • Alter - Modify Column
    • Alter - Rename Column
    • Alter - Drop Column
    • Copy Table
    • Drop Table
  • SQL Insert
    • Insert Record
  • Sql Update
    • Update Record
  • Sql Select
    • Select Record
    • Select - Count
    • Select - Average
    • Select - Sum
    • Select - Min Max
    • Select - Distinct
    • Select - Limit
    • Select - First
    • Select - Last
  • Sql Clause
    • Like Clause
    • And Operator
    • Or Operator
    • Between & Not Between Operator
    • As or Alias
    • In Clause
    • Group By Clause
    • Having Clause
  • Sql Order By
    • Ascending
    • Descending
    • Random
    • Ascending Descending Multiple Column
  • SQL Joins
    • Joins and its type
    • Inner Join
    • Left Join
    • Right Join
    • Full Join
    • Cross Join
  • SQL View
    • Create View
    • Update View
    • Delete View
  • SQL Delete
    • Delete Table
    • Truncate Table
  • Sql Key & Constraint
    • Primary Key
    • Foreign Key
    • Unique Key
    • Not Null Constraint
    • Check Constraint
    • Default Constraint
  • Normalization
    • Overview
    • 1 NF
    • 2 NF
    • 3 NF
    • Boyce Codd normal form ( BCNF )

About Fresherbell

Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique

Important Links

Don't hesitate to give us a call or send us a contact form message

Terms & Conditions
Privacy Policy
Contact Us

Social Media

© Untitled. All rights reserved. Demo Images: Unsplash. Design: HTML5 UP.