title: A practical example of denormalization in a SQL database?
body: <p>I've been reading about denormalization for the last 20 minutes but can't get a concise example with code.</p>
  
  <p>Is this what denormalization is? </p>
  
  <p><br>
  1. We have a normalized database:</p>
  
  <p><strong>Table_1:<br></strong>
  customer_id (Primary key)<br>
  country<br>
  city<br>
  street<br>
  house_number<br></p>
  
  <p><strong>Table_2: <br></strong>
  product_id (Primary Key)<br>
  customer_id (Foreign key)<br>
  product_storage_building<br></p>
  
  <p><strong>Table_3:<br></strong>
  product_id (Foreign Key) <br>
  product_name<br>
  product_color<br>
  product_origin<br></p>
  
  <ol start="2">
  <li><p>However, joining all three tables is taking far too long to run let's say</p>
  
  <pre><code>    SELECT a.*, b.*, c.*
      FROM 
      TABLE_1 AS a
      LEFT JOIN TABLE_2 AS b
      ON a.customer_id = b.customer_id
      LEFT JOIN TABLE_3 AS c
      ON b.product_id = c.product_id
  </code></pre></li>
  </ol>
  
  <p>So I create a new table out of <code>Table_1</code> and <code>Table_2</code></p>
  
  <pre><code>    CREATE OR REPLACE TABLE Denormalized_Data AS
      (
       SELECT customer_id, 
              country, 
              city,
              street, 
              house_number,
              product_id,
              product_storage_building
       FROM Table_1
            LEFT JOIN Table_2
            ON Table_1.cusomter_id = Table_2.customer_id
      )
  </code></pre>
  
  <ol start="3">
  <li><p>Then join to Table_3 as follows</p>
  
  <pre><code> SELECT customer_id, 
          country, 
          city,
          street, 
          house_number,
          product_storage_building,
          Denormalized_Data.product_id
          product_name,
          product_color,
       FROM Denormalized_Data
       LEFT JOIN Table_3
       ON Denormalized_Data.product_id = Table_3.product_id
  </code></pre></li>
  </ol>
  
  <p>Now this will make my query run faster - can the whole process above be described as denormalization?</p>
  
  <p>Thanks</p>