title: MySQL matrix multiplication
body: <p>I am trying to write matrix multiplication for MySQL and am kinda stuck: </p>
  
  <p>basically, my matrices are stored in format<br>
  [row#, column#, matrixID, value], so for example matrix [3 x 2] would be something like:</p>
  
  <pre><code>[row#, column#, matrixID, value]
    1      1        mat01    1
    1      2        mat01    2
    1      3        mat01    3
    2      1        mat01    4
    2      2        mat01    5
    2      3        mat01    6
  </code></pre>
  
  <p>being equivalent to: [[1 2 3],[4 5 6]]</p>
  
  <p>following does calculation of single element of matrix1 * matrix2 quite well: </p>
  
  <pre><code>   SELECT SUM(row1.`val` * col2.`val`)
     FROM matValues row1
     INNER JOIN  `matValues` col2
     WHERE row1.`row` = 1 AND row1.`mID`='matrix1' AND 
           col2.`mID`='matrix2' AND col2.`col` = 1 AND row1.col = col2.row
  </code></pre>
  
  <p>wrapping this into function and then using another function to iterate over row and column numbers might work, but I have problems with generating this set of numbers and iterating over them using SQL. 
  Any advice / suggestions are welcome</p>