Joining a Stream to a Window

A description of how to create an inquiry stream which receives a row whenever an inquiry is required. The row contained in this stream can be joined to a window which holds the desired data.

Here is an example of a simple join query that publishes the most recent trade for a stock whenever an inquiry is made for that stock symbol:

INSERT INTO TradeResults 
SELECT StockTrades.* 
FROM TradeInquiry, StockTrades 
KEEP LAST WHERE StockTrades.symbol = TradeInquiry.symbol 
GROUP BY StockTrades.symbol;

The TradeInquiry stream is a single column stream that receives a row with a stock symbol whenever someone needs to view the latest trade for that symbol. It can be thought of as a simple stream coming from a terminal, web page or other application. Here is the schema for the TradeInquiry stream:

Column

Datatype

Description

symbol

String

The symbol of the requested stock.

The StockTrades stream is directed into a KEEP LAST window which, because of the GROUP BY clause, keeps the last row for each symbol. (Without the GROUP BY clause, only the most recent trade for the entire StockTrades stream would be kept.)

The output stream schema for TradeResults is the same as the schema for StockTrades. The use of the qualified term StockTrades.* puts all of the columns from StockTrades, but not the symbol column from TradeInquiry, into the output stream,

Here is an illustration of how this simple join query works:



Here are some important things to notice about this simple join query:



Created March 8, 2010. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com