Between And Operator
Between And Operator in SQL is used to find a value or result in a range. Note that While Using BETWEEN AND Operator The Condition Should Apply From Lower To Higher.
Let's Understand working of BETWEEN AND operator with some examples:
1. WRITE A QUERY TO DISPLAY SALARY OF EMPLOYEE WHOSE SALARY IS BETWEEN 2000 TO 1200.
SQL> SELECT * FROM EMP
2 WHERE SAL BETWEEN 1200 AND 2000;
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7934 MILLER CLERK 7782 23-JAN-82 1300
10
2. WRITE A QUERY TO DISPLAY EMPLOYEE NAMES BETWEEN 'ALLEN' AND 'SMITH'.
SQL> SELECT * FROM EMP
2 WHERE SAL BETWEEN 1200 AND 2000;
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7934 MILLER CLERK 7782 23-JAN-82 1300
10
No comments:
Post a Comment