Creating an inner join: Exercise

Explore different syntax for an inner join.

In previous activities and exercises you worked with an inner join using the JOIN keyword. In this activity you will explore a different syntax for an inner join.

  1. Replace the word JOIN in the join Query statement with a comma (,) and then eliminate extra spaces. The Query statement should now look like this:
    -- Create the join
    
    INSERT INTO TradeResults
    SELECT TradeInquiries.Symbol, 
    	TradesWindow.Price,
    	GETTIMESTAMP(TradesWindow)
    FROM TradeInquiries, TradesWindow
    WHERE TradeInquiries.Symbol = TradesWindow.Symbol;
    
  2. Outside of Sybase CEP Studio, navigate to SybaseC8Repository/version/examples/GettingStarted/DataFiles (where version is the version number of Sybase CEP Engine) and then copy the file inquiries.csv to the directory data in the StockFilter project directory.
  3. Add the following text to the end of the contents in the Queries tab (or copy the text from CombiningSourcesCCL.txt between the lines "-- Combining Sources Code Block 3" and "-- Combining Sources Code Block 4"):
    -- Create an input adapter, which provides
    -- data to the TradeInquiries stream
    
    ATTACH INPUT ADAPTER TradeInquiriesReader 
    TYPE ReadFromCsvFileAdapterType
    TO STREAM TradeInquiries
    PROPERTIES 
    	FILENAME = "$ProjectFolder/data/inquiries.csv",
    	LOOPCOUNT = "5",
    	RATE = ".5",
    	USECURRENTTIMESTAMP = "YES",
    	TITLEROW = "YES",
    	TIMESTAMPCOLUMN = "NO"   
    

    This statement attaches an input adapter to the TradeInquiries stream and sets some of the adapter's properties.

  4. Run the project and then examine the output in TradeResults:


    traderesultswithadapter PNG

    Notice that the output is similar to the output you saw in the last exercise. Because of the Attach Adapter statement, multiple rows with different values in the Symbol column arrive on TradeInquiries, which in turn produces more output rows.

  5. Examine the Query statement in the Queries tab again:
    • This statement uses a comma instead of the word JOIN to create the inner join but produces the same results.

    • A comma-separated join is always an inner join and always uses a WHERE clause to create the join condition instead of an ON clause.

  6. Stop the project.

Exercise

Complete the following exercises to reinforce the join syntax. See Solutions for a possible solution to this exercise.