Skip to main content

Like

LIKE – case sensitive

SELECT * FROM Customers

WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%');

(Select all Spanish customers that starts with either "G" or "R")

Wildcards:

_ -> a single character, ex: Ajay -> like A _ _ _ , start with A then only 3 chars.

% -> any number of characters, even zero characters.

L% means start with L then n num of chars.

%A means let there be n number of chars before but end with A only.

B%s means start with B end with s

SELECT * FROM Customers WHERE Country LIKE 'Spain';

and

SELECT * FROM Customers WHERE Country = 'Spain'; => is correct

LIKE is a smell unless wildcards are used