SQL LIKE Operator


The SQL LIKE operator is used in a SQL WHERE clause to filter or extract records for a specified pattern using wildcards (character string matches a pattern) in a table column.

You can use SQL LIKE operator when only a fragment of a text value of a column is known to search.

The SQL LIKE operator supports only text based columns like "CHAR", "VARCHAR" or "TEXT" to match a pattern.

The SQL LIKE operator can be used with in any valid SELECT SQL statement.


SQL LIKE Syntax


SELECT column_name1, column_name2 FROM table_name 
WHERE column_name LIKE 'search pattern';


Search Keys

  • like sql
  • sql like operator
  • tsql like
  • mssql like
  • sql not like
  • sql like in
  • sql server like
  • how to use like in sql
  • sql like any
  • sql string like
  • sql search like
  • sql server not like
  • oracle select like
  • sql server like in
  • sql like in list
  • sql like example
  • sql string match like
  • sql in with like
  • sql like expression
  • sql server like query example
  • sql wildcard search
  • sql query to search for a string
  • sql search operators
  • sql search query examples
  • sql search wildcard

Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 A Visual Introduction To Sql 70 2008 Administration Nirmala
2 MySql Database Internals 140 2012 Optimization Sakunthala
3 Making Sense Of SQL 125 2010 Database Hanumanthan
4 Sql Server Cookbook 200 2007 Database Keshavan
5 PHP And MySQL Bible 150 2014 Optimization Azaghu Varshith
6 SQL Design Patterns 175 2010 Programming Siva Kumar
7 SQL Server 2008 Transact-Sql 170 2010 Database Ramanathan
8 SQL Functions Reference 205 2015 Optimization Vinoth Kumar
9 Complete Guide To No-SQL 195 2010 Database Ranjani Mai
10 From Access To SQL Server 115 2011 Programming Chandra
11 Pro MySql Administration 165 2009 Performance Keshavan
12 Postgre Sql Server Programming 123.45 2008 Performance Hari Krishnan

SQL LIKE Operator Example

The following SQL SELECT statement selects the all books with a BookName starting "Sql", in the "Books" table:


SELECT * FROM Books 
WHERE 
BookName LIKE 'Sql%';

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
4 Sql Server Cookbook 200 2007 Database Keshavan
6 SQL Design Patterns 175 2010 Programming Siva Kumar
7 SQL Server 2008 Transact-Sql 170 2010 Database Ramanathan
8 SQL Functions Reference 205 2015 Optimization Vinoth Kumar

The following SQL SELECT statement selects the all books with a BookName ending "Sql", in the "Books" table:


SELECT * FROM Books 
WHERE 
BookName LIKE '%Sql';

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 A Visual Introduction To Sql 70 2008 Administration Nirmala
3 Making Sense Of SQL 125 2010 Database Hanumanthan
7 SQL Server 2008 Transact-Sql 170 2010 Database Ramanathan
9 Complete Guide To No-SQL 195 2010 Database Ranjani Mai

SQL LIKE Operator Example With Multiple Columns

The following SQL SELECT statement selects the all books with a BookName starting "Sql" and Relyear ending "0", in the "Books" table:


SELECT * FROM Books 
WHERE 
BookName LIKE 'Sql%' AND RelYear LIKE '%0';

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
6 SQL Design Patterns 175 2010 Programming Siva Kumar
7 SQL Server 2008 Transact-Sql 170 2010 Database Ramanathan

SQL NOT LIKE Operator Example

The SQL LIKE condition can use with the SQL NOT operator.

The following SQL SELECT statement selects the all books with a BookPrice not starting "1", in the "Books" table.


SELECT * FROM Books 
WHERE 
BookPrice NOT LIKE '1%';

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 A Visual Introduction To Sql 70 2008 Administration Nirmala
4 Sql Server Cookbook 200 2007 Database Keshavan
8 SQL Functions Reference 205 2015 Optimization Vinoth Kumar

Search Keys

  • wildcard search sql
  • sql keyword search
  • sql string contains
  • sql contains
  • sql contains string
  • sql query contains
  • wildcard operator
  • wildcard matching
  • sql string match
  • match sql
  • sql partial string match
  • sql regex
  • sql server regex
  • mssql regex
  • oracle regex
  • regex sql
  • regexp_like examples
  • sql like regex
  • sql regex replace
  • oracle regexp match
  • t sql regexp
  • oracle pattern matching
  • sql pattern matching
  • regex like sql
  • sql server like command