LIKE Operator
The LIKE Operator is commonly used to select data based on patterns.
MySQL provides two wildcard characters for using with the LIKE operator ,the Percentage % and Underscore _ .The percentage (%) wildcard allows you to match any string of zero or more characters. The underscore( _ ) wildcard allows you to match any single character.
So ,to use this operator first we create a table with the below content.
Customer_id | Customer_Name | Mobile_No | Area |
80101 | DINESH RAJ | 9840212400 | THIRUNINRAVUR |
80102 | RAKESH RAJ | 9840312413 | AMBATTUR |
80103 | SUMATHI | 9489096200 | PERUNGUDI |
80104 | SHANKARAN | 8120191091 | THIRUNINRAVUR |
80105 | RAHUL | 9000234121 | THIRUNINRAVUR |
80106 | DIVAKAR | 9840312222 | PERUNGUDI |
80107 | DHARMENDAR | 9804316666 | THIRUNINRAVUR |
80108 | SHANMUGAM | 8120878787 | AMBATTUR |
80109 | PURUSOTH | 9080403020 | THIRUNINRAVUR |
So, From the above table to display all the customers of name ends with “RAJ” we need to use the following query..
Syntax:
SELECT * FROM 'customer_list' WHERE 'Customer_Name' LIKE "%RAJ"
So the result shows the name which contains “RAJ” …
IN Operator
The IN operator allows you to determine if a specified value matches any value in a set of values.
So, From the above table to display mobile numbers of the customers in AMBATTUR ,PERUNGUDI? we need to use the following query..
SELECT * FROM `customer_list WHERE Area IN ("AMBATTUR","PERUNGUDI")
So the result displays all the customers mobile numbers who are in AMBATTUR ,PERUNGUDI
BETWEEN Operator
The BETWEEN operator allows you to specify a range to test .
So, to explain this we will just take the random example.
Product_id | Description | Quantity | Price |
1004 | 4GB DDR4 RAM | 5 | 2100 |
1005 | Asus M5A78L-M Motherboard | 2 | 9852 |
1006 | GB N3050M Motherboard | 5 | 4890 |
1007 | GB 78LMT Motherboard | 2 | 6800 |
1008 | Dell 21.5 Inch LED Monitor | 5 | 6200 |
1009 | Asus 24 Inch LED Monitor | 5 | 8000 |
1010 | SanDisk Ultra 32GB USB | 10 | 550 |
So, to display all the products of price 500-2000 we need to use the following query..
SELECT * FROM 'products’ WHERE ‘price’ BETWEEN 500 AND 2000
So the results gives us by displaying the products whose price is between 500 to 2000.
1010 | SanDisk Ultra 32GB USB | 10 | 550 |