Using Various Operators Using WHERE Clause

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_idCustomer_NameMobile_NoArea
80101DINESH RAJ9840212400THIRUNINRAVUR
80102RAKESH RAJ9840312413AMBATTUR
80103SUMATHI9489096200PERUNGUDI
80104SHANKARAN8120191091THIRUNINRAVUR
80105RAHUL9000234121THIRUNINRAVUR
80106DIVAKAR9840312222PERUNGUDI
80107DHARMENDAR9804316666THIRUNINRAVUR
80108SHANMUGAM8120878787AMBATTUR
80109PURUSOTH9080403020THIRUNINRAVUR

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_idDescriptionQuantityPrice
10044GB DDR4 RAM52100
1005Asus M5A78L-M Motherboard29852
1006GB N3050M Motherboard54890
1007GB 78LMT Motherboard26800
1008Dell 21.5 Inch LED Monitor56200
1009Asus 24 Inch LED Monitor58000
1010SanDisk Ultra 32GB USB10550
Create a table of the content with given above.

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.

1010SanDisk Ultra 32GB USB10550
This is result of this Query.