Wednesday 29 May 2013

NOT Operator in SQL

Example:

The above example displays the name,job of employee whose job is not MANAGER or ANALYST.

Note:
The NOT operator can also be used with other SQL operators, such as BETWEEN, LIKE and NULL

-------- WHERE sal NOT BETWEEN 1000 AND 3000
-------- WHERE ename NOT LIKE '%K%'
-------- WHERE comm IS NOT NULL



OR Operator in SQL


  • OR requires either conditions to be TRUE. (i.e. any one condition should be satisfied)
Example:

In the above example either conditions can be true for any record to be selected. The employee can have sal >=2000 or his/her department number may be 10 or 20.

AND Operator in SQL


  • AND requires both conditions to be TRUE.
Example:

In the above example the results shown satisfies both the conditions to be displayed. 

Logical Conditions ( AND, OR, NOT Operators)


  • A Logical condition combines the result of two component conditions to produce a single based on them or inverts the result of a single condition.
  • A row is returned only if the overall result of the condition is true.
  • Three logical operators are available in SQL:

OPERATOR                             MEANING

AND                                         Returns TRUE if both component conditions are true.
OR                                            Returns TRUE if either component condition is true.
NOT                                         Returns TRUE if the following condition is false.

(For examples see next posts)