Ever tried searching for data in a database when you don’t know the exact value?

    Maybe you remember a name that starts with “A”… or contains “son”… but that’s it.

    That’s exactly where the LIKE operator in SQL comes in. It helps you search for patterns – not just exact matches. And honestly, once you understand it, your SQL becomes way more powerful.

    Let’s break it down step by step.

    What is the LIKE Operator in SQL?

    The LIKE operator in SQL helps you search for specific patterns in a column. Instead of matching exact values, it allows flexible searching.

    In simple words, It answers questions like:

    • “Starts with this?”
    • “Ends with that?”
    • “Contains something?”

    Why Use the LIKE Operator?

    Here’s the thing – in real-world databases, you rarely have perfect data.

    So instead of writing strict conditions, you use LIKE to:

    • Search partial text
    • Filter data based on patterns
    • Handle unknown or incomplete values

    Example:
    If you don’t know the full name “Johnson”, you can still find it using:
    LIKE ‘%son’

    Syntax of LIKE Operator

    Let’s keep it simple:

    SELECT column_name
    FROM table_name
    WHERE column_name LIKE pattern;

    The magic happens in the pattern.

    Wildcards in SQL LIKE

    Wildcards are special characters that define the search pattern. Let’s go one by one.

    1. % (Percent Wildcard)

    This is the most commonly used wildcard.  It represents zero, one, or multiple characters.

    Example:

    SELECT * FROM users
    WHERE name LIKE 'A%';

    👉 This will return:

    • Aman
    • Ankit
    • Ayesha

    Basically, anything that starts with “A”.

    2. _ (Underscore Wildcard)

    This one is more specific. It represents exactly one character.

    Example:

    SELECT * FROM users
    WHERE name LIKE '_a%';

    👉 This will match:

    • Raj
    • Sam

    But not:

    • Aman (because it has more characters before “a”)

    Common LIKE Patterns (Super Useful)

    Let’s look at patterns you’ll actually use:

    Pattern Meaning
    ‘A%’ Starts with A
    ‘%A’ Ends with A
    ‘%A%’ Contains A
    ‘A_%’ Starts with A + at least 2 characters
    ‘_A%’ Second letter is A

    👉 These patterns are super helpful in real queries.

    Practical Examples

    Let’s make this more real.

    Example 1: Find names starting with “J”

    SELECT * FROM users
    WHERE name LIKE 'J%';

    Example 2: Find emails containing “gmail”

    SELECT * FROM users
    WHERE email LIKE '%gmail%';

    Example 3: Find names ending with “n”

    SELECT * FROM users
    WHERE name LIKE '%n';

    Example 4: Fixed-length pattern

    SELECT * FROM users
    WHERE name LIKE 'R__';

    Matches:

    • Raj
    • Ron

    Common Mistakes to Avoid

    Let’s be real – beginners often mess up here.

    1. Forgetting Quotes

    Wrong:

    LIKE A%

    Correct:

    LIKE ‘A%’

    2. Confusing % and _

    • % → multiple characters
    • _ → single character

    3. Case Sensitivity Issues

    Some databases (like MySQL) are case-insensitive, others are not.

    👉 Always test your queries.

    Pro Tips (From Experience)

    Here’s what actually helps in real projects:

    • Use % wisely — too many wildcards can slow queries
    • Avoid starting with % when possible (‘%text’) → bad for performance
    • Combine LIKE with AND / OR for advanced filtering

    Example:  WHERE name LIKE ‘A%’ AND city LIKE ‘%Delhi%’

    Real-Life Use Cases

    You’ll use LIKE in:

    • Search bars (partial matching)
    • Email filtering
    • User name search
    • Data cleaning & filtering

    Basically, anywhere you need a flexible search.

    Bottom Line

    The LIKE operator in SQL might look simple at first… But once you start using it, you realize how powerful it actually is.

    It gives you flexibility. It saves time. And most importantly, it makes your queries smarter.

    So next time you don’t know the exact value…You know what to use.

    You Might Also Like – 
    1- UPDATE Query in SQL
    2- Create Table in SQL
    3- Delete Query in SQL

    Share.

    Vijay Chauhan is a tech professional with over 9 years of hands-on experience in web development, app design, and digital content creation. He holds a Master’s degree in Computer Science. At SchoolUnzip, Vijay shares practical guides, tutorials, and insights to help readers stay ahead in the fast-changing world of technology.

    Leave A Reply