title: MySQL: Long table vs wide table
body: <p>What is the more efficient (in terms of query performance) database table design - long or wide? </p>
  
  <p>I.e., this</p>
  
  <pre><code>id size price
  1  S    12.4  
  1  M    23.1
  1  L    33.3
  2  S    3.3
  2  M    5.3
  2  L    11.0
  </code></pre>
  
  <p>versus this</p>
  
  <pre><code>id  S     M     L
  1   12.4  23.1  33.3
  2   3.3   5.3   11.0
  </code></pre>
  
  <p>Generally (I reckon) it comes down to the comparison of performance between <code>GROUP BY</code> and selecting the columns directly:</p>
  
  <pre><code>SELECT AVG(price) FROM table GROUP BY size
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT AVG(S), AVG(M), AVG(L) FROM table
  </code></pre>
  
  <p>Second one is a bit longer to write (in terms of many columns), but what about the performance of the two? If possible, what are the general advantages/disadvantages of each of these tables formats?</p>