Conditional Operators In MySQL | ORACLE 11g Tutorials - Math Traders

Latest

Conditional Operators In MySQL | ORACLE 11g Tutorials

                                    conditional operators


Under conditional operators we will study operators which are used to perform some logical operations on the data in table.

These operators are: 

  • Greater Than ( > )
  • Greater Than Equal To ( >= )
  • Less Than ( < )
  • Less Than Equal To ( < = )
  • Equal To (=) 
  • Not Equal To ( != )


Let's understand these operators with one - one example for each.



1. WRITE A QUERY TO DISPLAY WHOSE SALARY IS GREATER THAN 1500.


SQL> SELECT ENAME, SAL FROM EMP
  2  WHERE SAL>1500;

ENAME             SAL
---------- ----------
ALLEN            1600
JONES            2975
BLAKE            2850
CLARK            2450
SCOTT            3000
KING             5000
FORD             3000

7 rows selected.


2. WRITE A QUERY TO DISPLAY ONLY THOSE EMPLOYEE WHO ARE NOT WORKING AS SALESMAN.


SQL> SELECT ENAME FROM EMP
  2  WHERE JOB != 'SALESMAN';

ENAME
----------
SMITH
JONES
BLAKE
CLARK
SCOTT
KING
ADAMS
JAMES
FORD
MILLER

10 rows selected.

OR


SQL> SELECT ENAME, JOB FROM EMP
  2  WHERE JOB!='SALESMAN';

ENAME      JOB
---------- ---------
SMITH      CLERK
JONES      MANAGER
BLAKE      MANAGER
CLARK      MANAGER
SCOTT      ANALYST
KING       PRESIDENT
ADAMS      CLERK
JAMES      CLERK
FORD       ANALYST
MILLER     CLERK

10 rows selected.
 
OR

SQL> SELECT ENAME FROM EMP
  2  WHERE JOB<>'SALESMAN';

ENAME
----------
SMITH
JONES
BLAKE
CLARK
SCOTT
KING
ADAMS
JAMES
FORD
MILLER

10 rows selected.

No comments:

Post a Comment