SRISTI SAGAR ROLL NO.
-72
EXPLICIT SETS
It is also possible to use an explicit set of values in the WHERE-clause rather than a nested query.
Explicitly mentioned rows can be
retrieved through IN operator.
Syntax-Diagram :test-expression
NOT
IN
constants )
,
SQL-Statement :SELECT <attribute-list> FROM <Table-name> WHERE <Column-name> IN (Constants)
Example :- Display the names of the employee who
belongs to department number 10,20 & 30. SELECT ENAME FROM EMP WHERE DEPTNO IN(10,20,30) ;
EMP
DEPTNO 20 30 40 20 10 ENAME SMITH ALLEN WARD JONES MARTIN MGR 7902 7698 7698
Output
ENAME
:-
SMITH
ALLEN JONES MARTIN
40
BLAKE
7566
The negated form of IN in NOT IN.
Advantage over nested query :-
Retrieve result in less time.
Advantage over comparison test :X IN ( A , B , C ) is completely equivalent to (X = A) OR ( X = B) OR (X = C)
So it is efficient to use Explicit Set here.
Meaning of NULL in SQL : Unknown Value Unavailable or Withheld Value Not applicable attribute NULL is used as a placeholder for unknown or missing values. Syntax-Diagram :column-name IS
NOT
NULL
NULL
SQL Statement :SELECT <attribute list> FROM <table name> WHERE <column-name> IS NULL/NOT NULL
The negated form of IS NULL is IS
NOT NULL.
Example :- Display the names of the
employees who do not have a manager(MGR).
SELECT ENAME FROM EMP WHERE MGR IS NULL;
EMP
DEPTNO
20 30 40 20 10 40
ENAME
SMITH ALLEN WARD JONES MARTIN BLAKE
MGR
7902 7698 7698 7566
ENAME
WARD MARTIN
We cant use = or != operator to test null
values. Reasons: SQL considers each NULL value as being distinct from every other NULL value . Also, NULL is not a real data value. While comparing with = operator SQL would search for NULL=NULL Values on both sides are unknown ,So the test doesnt produce a true result.
Example :SELECT ENAME FROM EMP WHERE MGR = NULL;
EMP
DEPTNO 20 30 40 20 10 40 ENAME SMITH ALLEN WARD JONES MARTIN BLAKE MGR 7902 7698
7698 7566
Output:no rows selected