How to correctly sort database results
<p>I have been asked to post a new question about how to correctly sort my data. Here is what I am trying to do. I want to make a single trip to my database for all of the data that I will need for this page. Once I have the data returned from the database, I need to sort it out and use it.</p>

<p>For brevity, I am only posting a single row of data. There are, in actuality, 8 rows being returned. Here is the structure of the data that is being returned:</p>

<pre><code>col1    col2    col3    col4    col5    col6    col7    col8    col9
</code></pre>

<p>Now, here is the problem I am having. Columns 1 through 7 hold a 1:1 dataset. Columns 8 and 9 however, hold numerous rows, hence the 8 total rows. Because I have columns 1 through 7 mixed in with the 1:M rows, I am echoing rows 1-7 7 times more than I need to.</p>

<p>How can I resolve this?</p>

<hr>

<p>Let me just add that there are 4 inner joins being used in this query. One of the tables, holds page specific data that I only need to access once. The other joins are what are creating the other rows. Let me just say tat the output of this resultset is absolutely correct. I just need to figure out how to sort it.</p>

<hr>

<p>OK, this should make sense....</p>

<pre><code>dealerId  empId  lotId  rackId  porterId  vehicle  vin
1         1      1      1       1         Geo      12JI997676JH
1         1      1      1       1         Ford     87HJ879854HS
1         1      1      1       1         BMW      567876HCS456
1         1      1      1       1         Mercedez 1JI8787GS687
</code></pre>

<p>In this set, notice that I have 4 rows of repeating data. What I need is this:</p>

<pre><code>dealerId  empId  lotId  rackId  porterId
1         1      1      1       1
</code></pre>

<p>AND then for the multiple rows, I need this:</p>

<pre><code>vehicle  vin
Geo      12JI997676JH
Ford     87HJ879854HS
BMW      567876HCS456
Mercedez 1JI8787GS687
</code></pre>

<p>So, this setup now gives me the <strong>single</strong> row of my dealer data and I now have a new array with the vehicle data. :)</p>
