Page 134 - SQL
P. 134

Chapter 36: LIKE operator




        Syntax



            •  Wild Card with % : SELECT * FROM [table] WHERE [column_name] Like '%Value%'

              Wild Card with _ : SELECT * FROM [table] WHERE [column_name] Like 'V_n%'


              Wild Card with [charlist] : SELECT * FROM [table] WHERE [column_name] Like
              'V[abc]n%'


        Remarks



        LIKE condition in WHERE clause is used to search for column values that matches the given
        pattern. Patterns are formed using following two wildcard characters

            •  % (Percentage Symbol) - Used for representing zero or more characters
            •  _ (Underscore) - Used for representing a single character


        Examples



        Match open-ended pattern


        The % wildcard appended to the beginning or end (or both) of a string will allow 0 or more of any
        character before the beginning or after the end of the pattern to match.


        Using '%' in the middle will allow 0 or more characters between the two parts of the pattern to
        match.

        We are going to use this Employees Table:


          Id  FName      LName       PhoneNumber        ManagerId      DepartmentId      Salary    Hire_date


                                                                                                   23-03-
          1   John       Johnson     2468101214         1              1                 400
                                                                                                   2005

                                                                                                   11-01-
          2   Sophie     Amudsen     2479100211         1              1                 400
                                                                                                   2010

                                                                                                   06-08-
          3   Ronny      Smith       2462544026         2              1                 600
                                                                                                   2015


                                                                                                   23-03-
          4   Jon        Sanchez     2454124602         1              1                 400
                                                                                                   2005

          5   Hilde      Knag        2468021911         2              1                 800       01-01-



        https://riptutorial.com/                                                                             116
   129   130   131   132   133   134   135   136   137   138   139