This example illustrates how to use the like operator in sql query.
The LIKE operator is used in a WHERE clause to search for matching strings based on the specified pattern in a column. The "%" wildcard can be used to specify the missing letters in the pattern. This wild card can be used at any place in the pattern. This example takes table emp for the query execution.
Source Code of likeOperator.php
The above query returns only the rows which has data in the name column having pattern '%sh%' i.e. The names which have 'sh' string in between and there may be any string before and after the 'sh' string.
In the query below, we want to find names which start from s.
|$result = mysql_query("select * from emp where name like 's%'");|
In the query below, we want to find names which end with h.
|$result = mysql_query("select * from emp where name like '%h'");|
In the query below, we want to find names in which a must be available.
|$result = mysql_query("select * from emp where name like '%a%'");|
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: January 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles