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

Explicit Sets & Nulls

1) The document discusses using the IN operator to retrieve rows where a column value matches one of several explicit values. 2) It provides an example querying employees belonging to departments 10, 20 or 30 using WHERE deptno IN (10,20,30). 3) The document also covers using IS NULL/IS NOT NULL to check for null values, giving an example finding employees without a manager using WHERE mgr IS NULL.

Uploaded by

sristisagar
Copyright
© Attribution Non-Commercial (BY-NC)
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)
20 views10 pages

Explicit Sets & Nulls

1) The document discusses using the IN operator to retrieve rows where a column value matches one of several explicit values. 2) It provides an example querying employees belonging to departments 10, 20 or 30 using WHERE deptno IN (10,20,30). 3) The document also covers using IS NULL/IS NOT NULL to check for null values, giving an example finding employees without a manager using WHERE mgr IS NULL.

Uploaded by

sristisagar
Copyright
© Attribution Non-Commercial (BY-NC)
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

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

You might also like