EXPLICIT SETS &
NULLS
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
IN
NOT
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) ;
Output
EMP
DEPTNO
ENAME
MGR
20
SMITH
7902
30
ALLEN
7698
40
WARD
20
JONES
7698
10
MARTIN
BLAKE
40
The negated
form of IN7566
in NOT IN.
ENAME
SMITH
ALLEN
JONES
MARTIN
:-
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.
NULL
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
NULL
NOT
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
ENAME
MGR
20
30
40
20
10
40
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
7902
7698
ENAME
WARD
MARTIN
7698
7566
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
ENAME
selected SMITH
20
30
40
20
10
40
ALLEN
WARD
JONES
MARTIN
BLAKE
MGR
7902
7698
7698
7566
Output:no rows