Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use LIKE operator in MySQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 687
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss how to use  LIKE operator in MySQL?

    Basically, LIKE operator is used for searching for a specified pattern in a column. So in other words we can say that the LIKE operator is used in a WHERE clause of SELECT, UPDATE and DELETE statement and also used to search for a specified pattern in a column.

    There are two wildcard characters(%,_) for pattern matching in like operator.
    1) "%" :- This wildcard characters is used for matching of zero or more characters.
    2) "_"  :- This wildcard characters is used for single character only.

    Syntax of LIKE operator:

    SELECT column_name(s)
    FROM table_name
    WHERE column_name LIKE pattern;
    

    You can see below example:

    Suppose we have table 'Users' which contains the details of user detail like id, name, username and city etc.

    If you want to get records of users whose name start with letter S.

    <?php
               $User_Detail = "SELECT * FROM `Users` WHERE `username` LIKE 'S%' "
      ?>

    The above query return all records of Users whose username start from letter S. for e.g. Sanjay, Suraj, Sandeep etc.

    If you want to get records of Users whose name end with letter L.

    <?php
                $User_Detail = "SELECT * FROM `Users` WHERE `username` LIKE '%L' "
        ?>

    The above query return all records of Users whose username end with letter L. for eg. Sunil, Anil Mangal etc.

    If you want to get records of Users whose with username  '_anjiv'

    <?php
    
          $User_Detail = "SELECT * FROM `Users` WHERE `username` LIKE '_anjiv' "
    
    ?>
    

    The above query return all records of Users whose username  with Sanjiv etc because (_) Wildcard is used to match a single character.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: