Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»MySQL case-sensitive Search with LIKE

    MySQL case-sensitive Search with LIKE

    By RahulSeptember 22, 20201 Min Read

    The LIKE statement is used for searching records with partial strings in MySQL. By default the query with LIKE matches case-insensitive recores. Means query will match both records in lowercase or uppercase.

    Advertisement

    For example, Search all records un colors table where name is start with “Gr”.

    1
    mysql> SELECT name FROM colors WHERE name LIKE 'Gr%';

    Mysql match all cases in LIKE

    You can see the above query matches records with any cases.

    But, sometimes you need to select case-sensitive data only. In that case, You need to cast the values as binary.

    To do this add BINARY option with like statment and view the results:

    1
    mysql>  SELECT name FROM colors WHERE name LIKE BINARY 'Gr%';

    Mysql case-sensitive LIKE query

    You can see the result contains only those records, which matches extactly with case-sensitive. When we use BINARY, then mysql compare data byte-by-byte. Without BINARY it compares data character-by-character.

    MySQL SQL
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Split Large Archives in Linux using the Command Line

    System.out.println() Method in Java: A Beginner’s Guide

    sleep Command in Linux with Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.