Learn From - Interactive SQL



SQL Like Operator


The Like operator is a wildcard operator and is used in the Where clause to retrieve data matching the given specified pattern.

Like operator Syntax


SELECT column_name, column_name..
FROM table_name
WHERE column_name LIKE specified pattern

The Like Operator Example


CustomerID CustomerName EmailID Address City PostalCode Country
C001 Fredrick Johnson FJohnson@yahoo.com Berkeley Gardens 12 Brewery London WX1 6LT UK
C002 Mary Davidson Mary@gmail.com 35 King George Madrid 28023 Spain
C003 George Clooney George@hotmail.com Obere Str. 57 Berlin 12209 Germany
C004 David Louis David@mail.com 2743 Bering St. NewJersy 07019 USA
C005 Johnny Anderson Johnny@gmail.com 55 Grizzly Peak Rd. NewJersy 07019 USA
C006 Paul Henriot PaulHenriot@yahoo.com 59 rue de l'Abbaye Paris 51100 France
C007 Henry King Henry@mail.com 120 Hanover Sq. London WA1 1DP UK
C008 Robert John Robert@gmail.com 87 Polk St. Suite 5 San Francisco 94117 USA

Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.

To retrieve records from the Customer table for countries starting with "U".

Select * from Customers
where Country like 'U%';

Note:The % sign is used like a wildcard. It can be used both before and after the specified pattern.

To retrieve records from Customer table for countries ending with "A".

Select * from Customers
where Country like '%A';

To retrieve records from Customer table with EmailID having the pattern "gmail".

Select * from Customers
where EmailID like '%gmail%';

To retrieve records from Customer table with EmailID not having this pattern "gmail".

Select * from Customers
where EmailID Not like '%gmail%';

SQL in Text Editor: