Friday, September 18, 2009

Rules of Precedence in SQL



Rules of Precedence :
  1. Arithmetic operators
  2. Concatenation operator
  3. Comparison conditions
  4. IS [NOT] NULL, LIKE, [NOT] IN
  5. [NOT] BETWEEN
  6. Not equal to
  7. NOT logical condition
  8. AND logical condition
  9. OR logical condition

Thursday, September 17, 2009

Using Logical Conditions in SQL Statement

Logical Conditions :



Operator Meaning
  • OR Returns TRUE if either component condition is true
  • AND Returns TRUE if both component conditions are true
  • NOT Returns TRUE if the following condition is false
Using the AND Operator :
  • AND requires both conditions to be true
  • SELECT empno, ename, sal FROM emp WHERE sal >=1000 AND job LIKE '%MAN%' ;
Using the OR Operator :
  • OR requires any condition to be true
  • SELECT empno, ename, sal FROM emp WHERE sal >=1000 OR job LIKE '%MAN%' ;
Using the NOT Operator :
  • SELECT empno, ename, job FROM emp WHERE sal >=1000 AND job NOT IN (‘CLERK’,’SALESMAN’) ;

Followers