WHERE clause

Specifies a selection condition for filtering input from data sources in a Query Statement, Database statement, or Remote Procedure statement, provides join conditions in the FROM Clause: Comma-separated syntax, update conditions in an Update Window statement, and delete conditions in a Delete statement.

Syntax

WHERE condition
Component

condition

A Boolean expression representing a selection, update, delete, or join condition, depending on the context.

Usage

WHERE is a versatile clause, used for filtering rows in several CCL statements, with similar syntax, but slightly different usage and context in each case.

AS SELECTION CONDITION

The first syntactical form of this clause is used optionally, in conjunction with single-source FROM clauses, as well as the FROM Clause: Join Syntax and FROM Clause: Database and Remote Subquery Syntax versions of the FROM clause. The Boolean expression specified in this clause creates a selection that filters rows arriving in the query's data sources before passing them on to the SELECT clause.

AS UPDATE CONDITION

When used in an Update Window statement, the expression in the WHERE clause specifies the criteria for updating existing rows in the named window specified in the UPDATE clause, with the values specified in the SET clause, when the update trigger occurs. If none of the rows in the window match the update criteria, new rows are inserted into the window, as indicated with the OTHERWISE INSERT clause, if one is present.

The WHERE clause is optional. In the absence of a WHERE clause, all rows in the window are updated when the trigger occurs. If no trigger for an update occurs, no rows are updated or inserted, whether or not a WHERE clause is specified.

AS DELETE CONDITION

When used in a Delete statement, the expression in the WHERE clause specifies the criteria for deleting rows from the named window indicated in the statement, once the deletion trigger occurs. This clause is optional. In the absence of a WHERE clause, all rows are deleted from the window when the trigger occurs. If no trigger for deletion occurs, no rows are deleted from the window, whether or not a WHERE clause is specified.

AS JOIN CONDITIONS

When used in conjunction with the FROM Clause: Comma-Separated Syntax form of the FROM clause, the WHERE clause creates one or more join condition for the comma-separated join. The use of a WHERE clause is optional in a comma-separated join. In the absence of a join condition, all rows from all data sources are selected. When a WHERE clause is present, its syntax resembles the ON Clause: Join Syntax (which is not used with comma-separated joins). The join condition can be any valid Boolean expression that specifies the condition for the join. All column references in this form of the WHERE clause must refer to data sources specified with the FROM clause.

CCL Subqueries

The selection condition or delete condition expression (but not the update condition or join condition) of the WHERE clause can include scalar CCL subqueries using the following syntax:

( select_clause from_clause [matching_clause] [on_clause] [where_clause] [group_by_clause] [having_clause] [output_clause] )
Components

select_clause

The select list specifying what to publish. See SELECT Clause for more information.

from_clause

The data sources. See FROM Clause for more information.

matching_clause

A pattern-matching specification. See MATCHING Clause for more information.

on_clause

A join condition. See ON Clause for more information.

where_clause

A selection condition. See WHERE Clause for more information.

group_by_clause

A partitioning specification. See GROUP BY Clause for more information.

having_clause

A filter definition. See HAVING Clause for more information.

output_clause

A synchronization specification. See OUTPUT Clause for more information.

The subquery is enclosed in parentheses and follows the same syntax as the Query statement, but without an INSERT clause and without the final semicolon. Subqueries in the WHERE clause are only permitted when they produce scalar output (one row per execution of the query). Aggregate output is not permitted, though aggregate functions can be used in the SELECT and HAVING clauses of the subquery to produce a single line of output from multiple lines. A subquery in the WHERE clause cannot directly reference a data stream or window in the parent or outer query and vice versa. WHERE clause subqueries can be nested.

Restrictions

See Also

Examples

The following example uses a subquery in the WHERE clause. The selection condition is used to produce a continuous stream of Boolean values that indicate whether or not a stock price is at least $1.00 above the moving average:

INSERT INTO OutStream
SELECT *
FROM Trades
WHERE Trades.Price > 1.00 + 
   (SELECT AVG(Price) 
    FROM Trades KEEP 100 ROWS);

The following WHERE clause defines a selection condition for a join:

INSERT INTO OutStream
SELECT Trades.Symbol, Trades.Price, Broker.Name
FROM Trades KEEP 1 DAY, Broker KEEP 1 DAY
WHERE Trades.Name = Broker.Name;

The following example updates the Status column of MyWindow for all rows that contain the same symbol as the symbol arriving in the triggering InStream:

ON InStream
UPDATE MyWindow
SET MyWindow.Status = "SOLD"
WHERE InStream.Symbol = MyWindow.Symbol;

The following example specifies that whenever a row with the message "Clear Window" arrives in the stream InStream, rows with the same value in the Symbol column as the arriving row should be deleted from the NamedWin window:

ON InStream
WHEN InStream.Message = 'Clear Window'
DELETE FROM NamedWin
WHERE InStream.Symbol = NamedWin.Symbol;