Tuple condition
-
Recall: the
basic
SELECT syntax:
select attribute-list
from relation-list
where condition
|
- The condition
in the where clause
is known as:
Reason:
- The where
condition is
applied to
the following
set
of
tuples:
select attribute-list
from relation-list
|
|
|
All the possible
tuple conditions in SQL
- The tuple condition can be
one of the
following
operation:
- atomic-value
relational-Oper
atomic-value (we have seen this before)
- The membership
test operator
(IN and NOT IN)
- The any
selection operator
(ANY)
- The all
selection operator
(ALL)
- The non-empty set
test operator
(EXISTS)
- The null
test operator
(IS NULL)
- The wild card
test operator
(LIKE)
-
AND,
OR and
NOT
expressions with
any of the
above
tuple conditions
|
|
Tuple condition 1: "traditional"
boolean condition
Tuple condition 2: membership test
(IN)
- The
membership test operator
IN
tests whether a
value
is contained
in a
set of
values
- Syntax:
atomic-value IN ( set of values )
|
meaning:
- The expression evaluates to
true if:
- atomic-value is a
member of the
( set of values )
|
- Otherwise,
the expression evaluates to
false
|
- Example:
SELECT fname, lname
FROM employee
WHERE ssn IN ('123456789', '333445555');
|
|
Tuple condition 2(A): NON-membership test
(NOT IN)
- The
membership test operator
NOT IN
tests whether a
value
is not contained
in a
set
- Syntax:
atomic-value NOT IN ( set of values )
|
meaning:
- The expression evaluates to
true if:
- atomic-value is
not a
member of the
( set of values )
|
- Otherwise,
the expression evaluates to
false
|
- Example:
SELECT fname, lname
FROM employee
WHERE ssn NOT IN ('123456789', '333445555');
|
|
Attention: Pedagogical alert
- Pedagogical alert:
- I value
understandability
above
complete correctness
|
- What I am going to
show you
next is
- not
completely correct !!
|
- However:
- The explanation
makes the
concept(s) a whole lot
easier
to understand.
|
|
The ANY selector
- Syntax of
the
ANY
tuple condition:
atomic-value RelationalOperator any ( set of values )
RelationalOperator is one of: =, !=, <, <=, >, >=
Example:
salary >= any ( set of values )
|
meaning:
|
The ANY selector -
example
The ANY selector -
the correct syntax
The ALL selector
- Syntax of
the
ANY
tuple condition:
atomic-value RelationalOperator all ( set of values )
RelationalOperator is one of: =, !=, <, <=, >, >=
Example:
salary >= all ( set of values )
|
meaning:
|
The ALL selector -
example
The non-empty set test
- Syntax of
the
non-empty set
test:
exists ( set of values )
Example: (incorrect but illustrative)
exists ( 'a', 'b' ) // returns true (= not empty)
exists ( ) // returns false (= empty set)
|
meaning:
- The expression evaluates to
true if:
( set of values ) is not empty
|
- Otherwise,
the expression evaluates to
false
|
|
Attention: Pedagogical alert
CANCELED
- The
pedagogical alert is
CANCELED
- From now on,
examples are
syntactically
correct
|
|
Checking for NULL values
- Testing if some attribute value
(in a tuple) contains the
NULL value:
- Example: find all employee tuples
that has a
NULL value in
the salary attribute:
SELECT *
FROM employee
WHERE salary IS NULL
|
- Note:
- To test
if a attribute value is
not equal to NULL, use:
|
|
Wild card string match (LIKE)
- When
comparing
strings ,
you can use the
LIKE
operator
to perform
wildcard
string comparison
- Special
wildcard characters:
- Example:
(finds employees
with last name that
starts with the
letter S)
SELECT fname, lname
FROM employee
WHERE lname LIKE 'S%'
|
|
Summary: all the possible
tuple conditions in SQL
- The tuple condition can be
one of the
following
operation:
- atomic-value
relational-Oper
atomic-value (we have seen this before)
- The membership
test operator
(IN and NOT IN)
- The any
selection operator
(ANY)
- The all
selection operator
(ALL)
- The non-empty set
test operator
(EXISTS)
- The null
test operator
(IS NULL)
- The wild card
test operator
(LIKE)
-
AND,
OR and
NOT
expressions with
any of the
above
tuple conditions
|
|
❮
❯