• Home
  • SQL LIKE Operator

    The LIKE operator in SQL is used to search for a specified pattern in a column. It is used along with the WHERE clause of the UPDATE, DELETE and SELECT statements, to filter the rows based on the given pattern. These patterns are specified using 'Wildcards'.

    The two most common wildcards used with the LIKE operator are:

    "%" - Represents zero, one, or multiple characters.
    "_"- Represents one, single character.


    For example, the following query will return all rows from the customers table where the customer_name column starts with the letter "A":

    SQL
    SELECT * FROM customers
    WHERE customer_name LIKE 'A%';

    The % wildcard can also be used at the end of a pattern to match zero or more characters at the end of the string. For example, the following query will return all rows from the customers table where the customer_name column ends with the letter "s":


    SQL
    SELECT * FROM customers
    WHERE customer_name LIKE '%s';

    The _ wildcard can be used to match a single character at any position in the string. For example, the following query will return all rows from the customers table where the customer_name column contains the letter "a" in the second position:


    SQL
    SELECT * FROM customers
    WHERE customer_name LIKE '_a_';

    The LIKE operator can also be used to match patterns that contain multiple wildcards. For example, the following query will return all rows from the customers table where the customer_name column contains the letters "ab" anywhere in the string:


    SQL
    SELECT * FROM customers
    WHERE customer_name LIKE '%ab%';

    The LIKE operator is a powerful tool that can be used to search for specific patterns in SQL data. By using wildcards, you can match patterns that would be difficult or impossible to match with other operators.


    Here are some other examples of how to use the LIKE operator in SQL:

    To match a string exactly, you can use the LIKE 'string' syntax.
    To match a string that starts with a certain value, you can use the LIKE 'value%' syntax.
    To match a string that ends with a certain value, you can use the LIKE '%value' syntax.
    To match a string that contains a certain value anywhere in the string, you can use the LIKE '%value%' syntax.
    To match a string that is case-insensitive, you can use the LOWER(column_name) LIKE LOWER('value') syntax.



    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext