title: How to join three or more datastreams /tables on a given key and a common window by datastrem API or Flink Table API/SQL?
body: <p>I want to Join <strong>three or more</strong> data streams or tables on a given key and a common window. however I don't know how to correctly write the code.
  The official document <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.5/dev/stream/operators/" rel="nofollow noreferrer">https://ci.apache.org/projects/flink/flink-docs-release-1.5/dev/stream/operators/</a> give the example below, however it just join two data streams , so how to join <strong>three or more</strong> data streams on a given key and a common window?</p>
  
  <pre><code>dataStream.join(otherStream)
  .where(&lt;key selector&gt;).equalTo(&lt;key selector&gt;)
  .window(TumblingEventTimeWindows.of(Time.seconds(3)))
  .apply (new JoinFunction () {...});
  </code></pre>
  
  <p>I tried to figure out that I join the two data streams firstly with common window, and use the result data stream to join third data stream with common window? However it seems the semantic of event time for these three data streams would be changed when we set the TimeCharacteristic to event time.</p>
  
  <p>==================</p>
  
  <p>The same question for FlinK Table API and SQL,how to join <strong>three or more</strong> tables on a given key and a common window? The official document <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.5/dev/table/sql.html" rel="nofollow noreferrer">https://ci.apache.org/projects/flink/flink-docs-release-1.5/dev/table/sql.html</a> just give the example below for single table.</p>
  
  <pre><code>Table result1 = tableEnv.sqlQuery(
  "SELECT user, " +
  "  TUMBLE_START(rowtime, INTERVAL '1' DAY) as wStart,  " +
  "  SUM(amount) FROM Orders " +
  "GROUP BY TUMBLE(rowtime, INTERVAL '1' DAY), user");
  </code></pre>
  
  <p>I tried to write the SQL like below to join three tables  on a given key and a common window , however I don't think it is right.</p>
  
  <pre><code>String SQL = "SELECT" +
              " grades.user1  , SUM(salaries.amount)   FROM grades " +
              " INNER JOIN salaries ON   grades.user1 =   salaries.user1 " +
              " INNER JOIN person ON   grades.user1 =   person.user1 "+
               "GROUP BY grades.user1, TUMBLE(grades.proctime,  INTERVAL '5' SECOND) "   
  </code></pre>
  
  <p>So what's the correct way to join three or more datastreams /tables on a given key and a common window by datastrem API or Flink Table API/SQL ?</p>
  
  <p><strong>update</strong> at 6/16/2018 to make the question more clearly.</p>
  
  <p>For the Flink SQL, what I needed , just like the Pseudocode below, is the join three tables with a common TumblingEventTimeWindow, that is to say the alternative version for DataStream API, however expressed by Flink SQL,a<em>lso meaning join all events from three tables, which happened in the same TumblingEventTimeWindow.</em></p>
  
  <pre><code>SELECT A.a, B.b, C.c
  FROM A, B, C
  WHERE A.x = B.x AND A.x = C.x AND
  window(TumblingEventTimeWindows.of(Time.seconds(3))
  </code></pre>
  
  <p>It seems that join feature also mentioned in the following Flink design document:
  "Event-time tumbling-windowed Stream-Stream joins: Joins tuples of two streams that are in the same tumbling event-time window", I have no idea if the Flink SQL  have implemented this type of Flink SQL  join feature.</p>
  
  <p><a href="https://docs.google.com/document/d/1TLayJNOTBle_-m1rQfgA6Ouj1oYsfqRjPcp1h2TVqdI/edit#" rel="nofollow noreferrer">https://docs.google.com/document/d/1TLayJNOTBle_-m1rQfgA6Ouj1oYsfqRjPcp1h2TVqdI/edit#</a></p>