SQL LIKE Operator



SQL LIKE Operator

SQL LIKE Operator – The SQL LIKE operator is used to returns all rows from a table whose column value match a specific pattern.

The LIKE Operator is mostly used to search engine. if we want to make search box in website then we use LIKE operator to display the search result.

We will understand how to use LIKE operator in sql in this sql tutorial with example.

The  SQL LIKE Operator Syntax :

SELECT Col1, Col2 FROM table_name WHERE Col1 LIKE  ‘m%’

m% – means returns those records whose col1 value start with m character.
%m – means returns those records whose the col1 value end with m character.
%m% – means returns those records whose  col1 value contain m character.

The SQL LIKE Operator Example :

Here, we have table Student with below records.

The SQL Student Table :

ID Name City Email
1 Meera Bombay meera@yahoo.com
2 Ram Surat ram@yahoo.com
3 Manoj Bombay manoj@yahoo.com
4 Vaidehi Ahmedabad meera@yahoo.com

 

Select those student records whose name start with m.

SELECT * FROM Student WHERE Name LIKE ‘m%’

The Result of SQL LIKE Operator :

ID Name City Email
1 Meera Bombay meera@yahoo.com
3 Manoj Bombay manoj@yahoo.com

 

Leave a Reply

Your email address will not be published. Required fields are marked *