Monday, 11 February 2013

SQL BETWEEN Operator Syntax and Example

SQL Server BETWEEN Operator
The SQL BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.

Syntax:
SELECT column_name(s) FROM table_name WHERE column_name
BETWEEN Value1 AND Value2

Example :

Let us suppose we have and EMP Table as follows :


E_Id
First_Name
Last_Name
Dept_Id
Address
Salary
1001
Ravi
Kumar
1
Hyderabad
20000
1002
David
Smith
2
Bangalore
35000
1003
Victory
Venkatesh
1
Hyderabad
50000
1004
Tamatam
Reddy
3
Bangalore
25000
1005
William
Smith
2
Hyderabad
40000
1006
King
Fisher
6
Bangalore
30000

Criteria :
Now we want to select the Employees whose salary between 30000 and 50000 as follows :

Select *from EMP E WHERE E.Salary BETWEEN 30000 and 50000

Result :



E_Id
First_Name
Last_Name
Dept_Id
Address
Salary
1002
David
Smith
2
Bangalore
35000
1003
Victory
Venkatesh
1
Hyderabad
50000
1005
William
Smith
2
Hyderabad
40000
1006
King
Fisher
6
Bangalore
30000



No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts