title: Obtain data from SQL and loop in different order
body: <p>in my application I need to operate with data obtained from SQL SERVER. At first, I grab 5 elements from <code>table1</code>:</p>
  
  <pre><code>example 1
  example 2
  example 3
  example 4
  example 5
  </code></pre>
  
  <p>And now, for <strong>each element in</strong> <code>array1</code> I grab 3 elements from <code>table2</code></p>
  
  <pre><code>foo 1
  foo 2
  foo 3
  foo 4
  foo 5
  foo 6
  foo 7
  foo 8
  foo 9
  foo 10
  foo 11
  foo 12
  foo 13
  foo 14
  foo 15
  </code></pre>
  
  <p>Allright. What I would like to do now is to loop them in that order:</p>
  
  <p><a href="https://i.stack.imgur.com/WhLG9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WhLG9.png" alt="image1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/vMNmy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vMNmy.png" alt="image2"></a></p>
  
  <p>(I cant post third image because Im new member, but you know the idea.)</p>
  
  <p>To do this I adeed data to arrays:</p>
  
  <pre><code>arrayExample[5]
  +----------+
  | example0 |
  +----------+
  | example1 |
  +----------+
  | example2 |
  +----------+
  | example3 |
  +----------+
  | example4 |
  +----------+
  
  arrayFoo[5,3]
  +--------+--------+--------+
  | foo 0  | foo 1  | foo 2  |
  +--------+--------+--------+
  | foo 3  | foo 4  | foo 5  |
  +--------+--------+--------+
  | foo 6  | foo 7  | foo 8  |
  +--------+--------+--------+
  | foo 9  | foo 10 | foo 11 |
  +--------+--------+--------+
  | foo 12 | foo 13 | foo 14 |
  +--------+--------+--------+
  </code></pre>
  
  <p>And I loop them with:</p>
  
  <pre><code>    for (int i=0; i&lt;3; i++)
      {
          for (int j=0; j&lt;5; j++)
          {
              DoActions(arrayExample[j], arrayFoo[i,j]);
          }
      }
  </code></pre>
  
  <p>And It works. But now I would like to get more data from SQL server. I would need to create more and more dimensions of my arrays. I think its too complicated. There must be a better solution to do this.</p>
  
  <p>tl;dr</p>
  
  <p>I want to grab 5 elements <code>EXAMPLE</code> and each of wchich should have assigned 3 <code>FOO</code> elements.</p>
  
  <p>Now loop every elements with first <code>FOO</code> asigned, then second and then third.</p>
  
  <p>DO you have any better idea than mine?</p>