0% found this document useful (0 votes)
160 views10 pages

Explicit Sets & Nulls

This document discusses explicit sets and null values in SQL. It defines explicit sets as using an explicit list of values in the WHERE clause rather than a nested query. This can retrieve rows using the IN operator more efficiently than a comparison or nested query. Null values represent unknown, unavailable, or not applicable attribute values. The IS NULL and IS NOT NULL operators are used to test for null values, since normal equality operators like = will not work with nulls.

Uploaded by

sristisagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views10 pages

Explicit Sets & Nulls

This document discusses explicit sets and null values in SQL. It defines explicit sets as using an explicit list of values in the WHERE clause rather than a nested query. This can retrieve rows using the IN operator more efficiently than a comparison or nested query. Null values represent unknown, unavailable, or not applicable attribute values. The IS NULL and IS NOT NULL operators are used to test for null values, since normal equality operators like = will not work with nulls.

Uploaded by

sristisagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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

You might also like