Wednesday, July 16, 2014

Between and In Operators in SQL

Between Operator

It is used to select values within a range.



Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;


For example:

We have a table like below:

eid name address email mobile joiningdate
1 Ryan Ktm ryan@gmail.com 9874512663 2014/01/24
2 Sunaina Lagankhel s@gmail.com 98745256325 2014/03/12
3 Preeti Budhanagar p@gmail.com 987412321 2014/05/08

Now if you want to find those employees who have joined between '2014/01/01' and '2014/03/30'.

Then simply use the SQL as below:

SELECT * FROM  tbl_employees WHERE  joiningdate   BETWEEN  '2014/01/01'  AND  '2014/03/30' 

IN Operator 
In the above table if you need to list those employees who lives in Lagankhel and Budhanagar then you can use SQL as below:

SELECT * FROM  tbl_employees WHERE  address  IN ('Lagankhel','Ktm')


 

No comments:

Post a Comment