Entering content frame

IN Predicate (in_predicate) 

The IN predicate checks whether a value or a value list is contained in a specified set of values or value lists.

Syntax

<in_predicate> ::=
  <expression> [NOT] IN <subquery>
| <expression> [NOT] IN <expression_list>
| <expression_list> [NOT] IN <subquery>
| <expression_list> [NOT] IN (<expression_list>,...)

expression, expression_list, subquery

Explanation

The subquery must supply a result table (see result table name) that contains the same number of columns as the number of values specified by the expression on the left-hand side of the IN operator.

Each value list specified on the right-hand side of the IN operator must contain the same number of values as specified in the value list on the left-hand side of the IN operator.

·        x [NOT] IN S, whereby x <expression>and S <subquery> or <expression_list>
The value x and the values in S must be comparable.

·        x [NOT] IN S, whereby x <expression_list> with the values x1, x2, ..., xn and S <subquery>(set of value lists s) or (<expression_list>,...) (Range of values lists s) with the value lists s: s1, s2, ..., sn
A value xm must be comparable with all values sm.
x=s is true if xm=sm, m=1,...,n
x=s is false if there is at least one m for which xm=sm is false
x=s is undefined if there is no m for which xm=sm is false and there is at least one m for which xm=sm is undefined.

The entry '------' in the list below means that no statement can be made if only the result of the comparison with one s is known.

 

Result of the function x IN S

x=s is true for at least one s

true

x=s is true for all s

true

S contains NULL values and x=s is true for the remaining s

true

S is empty

false

x=s is false for at least one s

------

x=s is false for all s

false

S contains NULL values and x=s is false for the remaining s

undefined

x=s is not true for any s and is undefined for at least one value s

undefined

x NOT IN S has the same result as NOT(x IN S)

Example table: customer

Choosing all customers who are natural persons (not companies):

SELECT title, firstname, name, city FROM customer
WHERE title IN ('Mr','Mrs')

TITLE

FIRSTNAME

NAME

CITY

Mrs

Jenny

Porter

New York

Mr

Martin

Porter

Los Angeles

Mrs

Sally

Peters

Los Angeles

Mr

Peter

Brown

Hollywood

Mr

Michael

Porter

New York

Mr

George

Howe

New York

Mr

Frank

Randolph

Los Angeles

Mr

Joseph

Peters

Los Angeles

Mrs

Susan

Brown

Los Angeles

Mr

Anthony

Jackson

Los Angeles

Mr

Thomas

Adams

Los Angeles

Mr

Mark

Griffith

New York

Mrs

Rose

Brown

Hollywood

 

 

Leaving content frame