MySql- IN and BETWEEN operators in MySql


BETWEEN in MySQL


BETWEEN Operators are used to select a values within a range or scope .
Syntax:
Select coulmns_names from table_name WHERE coulmn_name BETWEEN value1 AND value2;
Example:
For below table structure:
p_id pro_name price
1 Samsung 100
2 Reliance 80
3 Vodafone 90
4 Idea 85
Example query for BETWEEN
SELECT * from product WHERE price BETWEEN  80 AND 90;  
Output
P_id Pro_name Price
2 Reliance 80
3 Vodafone 90
4 Idea 85

IN operators in MySQL


IN operators are use to assign multipal values and select data on behalf.
Select coulmns_names from table_name WHERE coulmn_name IN (value1,value2......); 
Example:
Below is a user table:
U_id Uname Mobile City
1 Raj UMOBILE1 Ajmer
2 Ravi UMOBILE2 Jaipur
3 Vijay UMOBILE3 Alwar
4 Pawan UMOBILE4 Jaipur
Example query for IN
SELECT * FROM user WHERE city IN('Ajmer','Jaipur');  
Output
U_id Uname Mobile City
1 Raj UMOBILE1 Ajmer
2 Ravi UMOBILE2 Jaipur
4 pawan UMOBILE4 Jaipur

No comments:

Post a Comment