Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Wildcard with LIKE operator in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 635
    Comment on it

    In SQL, LIKE clause is basically used to search the homogeneous data using wildcard from a database. The LIKE operator is used to find out  the particular string from a table's field into database.

    Some wildcard examples are given as below..

     

    % Wildcard with SQL:

     

    Example1: SELECT * FROM users WHERE  first_name LIKE 'del%';

    The above sql syntax selects all users from users table whose first_name is starting with 'del' string.

     

    Example2: SELECT * FROM users WHERE  first_name LIKE '%del';

    The above sql syntax selects all users from users table whose first_name is ending with 'del' string.

     

    Example3: SELECT * FROM users WHERE city_name LIKE  '%bad%';

    The above sql syntax selects all users from users table which having first_name sequence like  "bad".

     

     

    _ Wildcard with SQL:

     

    Example1: SELECT * FROM locations WHERE city_name LIKE '_est';

    The above sql syntax selects all locations from locations table whose first character of city_name is starting with any character and should be followed by "est"

     

    Example2: SELECT * FROM locations WHERE city_name LIKE 'N_w_elhi';

    The above sql syntax selects all locations from locations table which is start with "N" followed by any single character then followed by "w" again followed by any single character and then followed by "elhi"

     

    [charlist] Wildcard with SQL:

    In this type of  wildcard we can pass the optional search keys i.e. more than one search keys.

     

    Example1: SELECT * FROM locations WHERE country_name LIKE '[abc]%';
    The above example we selects all locations with a country_name which has starting with "a", "b", or "c"

     

     

    Example2: SELECT * FROM locations WHERE country_name LIKE '%[abc]';
    The above query is used to selects all locations with a country_name which has ending with "a", "b", or "c"

     

    If there is a requirement to search records with in a range then we can use the below syntax

    Example3: SELECT * FROM locations WHERE country_name LIKE  '[d-f]%';
    The above statement selects all locations with a country_name starting with "d", "e", or "f"

     

     

     

     

 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: