title: Difference between df.SaveAsTable and spark.sql(Create table..)
body: <p>Referring to <a href="https://stackoverflow.com/questions/47844808/what-are-the-differences-between-saveastable-and-insertinto-in-different-savemod">here</a> on the difference between saveastable and insertInto</p>
  
  <p>What is the difference between the following two approaches :</p>
  
  <pre><code>df.saveAsTable("mytable");
  </code></pre>
  
  <p>and</p>
  
  <pre><code>df.createOrReplaceTempView("my_temp_table");
  spark.sql("drop table if exists " + my_temp_table);
  spark.sql("create table mytable as select * from 
  my_temp_table");
  </code></pre>
  
  <p>In which case is the table stored in memory and in which case physically on disk ?</p>
  
  <p>Also, as per my understanding, <code>createOrReplaceTempView</code> only register the dataframe (already in memory) to be accessible through Hive query, without actually persisting it, is it correct ? </p>
  
  <p>I have to Join hundreds of tables and hit OutOfMemory issue.
  In terms of efficiency, what would be the best way ? </p>
  
  <ul>
  <li><p><code>df.persist()</code> and df.join(..).join(..).join(..).... #hundred joins</p></li>
  <li><p><code>createOrReplaceTempView</code> then join with <code>spark.sql()</code>, </p></li>
  <li><p><code>SaveAsTable</code> (? not sure the next step)</p></li>
  <li><p>Write to disk with <code>Create Table</code> then join with <code>spark.sql()</code>?</p></li>
  </ul>