title: How to make a list of PrimaryRowId and Matching RowIds
body: <p>In my previous question (<a href="https://stackoverflow.com/questions/14629325/select-a-distinct-rowid-based-on-series-of-trainnumbers">Select a distinct RowId based on series of trainnumbers</a>) I got a nice list of RowIds.</p>
  
  <p>Now I'd like to make that list complete and totally awesome! :)</p>
  
  <p>My raw data(Excel 2010) looks like this:</p>
  
  <pre><code>Time    Wagons     Delete     DayType    Plate    trainnumber   RowId
  05.28    1                       1      0901-046     2          38676
  08.20    2                       1      0901-003     2          18676
  05.25    2            x          1      0901-046     2          28676
  15.28    2                       1      0901-046     2          3676
  23.20    3                       1      0601-001     2          3867
  05.08    3                       1      0901-046     2          3876
  00.28    L            x          1      0901-046     2          8676
  00.00                            1      0901-046     2          367
  </code></pre>
  
  <p>I need a list that groups the Primary RowIds(the list from the previous question) with the RowIds that match it by the following criteria:</p>
  
  <ul>
  <li>on the Primary and Matching rows the following must be the SAME:
  
  <ul>
  <li>trainnumber</li>
  <li>DayType</li>
  <li>Time</li>
  </ul></li>
  <li>on the Primary and Matching rows the Plate must be DIFFERENT</li>
  <li>Wagons must be MORE THAN 1 (The column contains rows with numbers, letters and nothing)</li>
  <li>Delete must be empty</li>
  </ul>
  
  <p>When matches are found, I need the RowId of the match.</p>
  
  <p>Ideally a dataset like this:</p>
  
  <pre><code>PrimaryRowId    Match#1    Match#2    Match#3    Match#4
  15674            5465        456       5456        45656
  5564             231         132       1321        7862
  </code></pre>
  
  <p>It's possible that there's more matches per Primary RowId, but that's ok.</p>
  
  <p>My SQL skills is somewhat limited, so that's why I'm asking you guys. :)</p>
  
  <p>I <em>think</em> it might be something like this:</p>
  
  <pre><code>SELECT RowId
  FROM Conversion
  WHERE trainnumber=trainnumber and daytype=daytype and 
        time=time and plate&lt;&gt;plate and Wagons&gt;1 and delete="" 
  GROUP BY RowId
  </code></pre>
  
  <p>But it would only give me one(1) RowId at a time. :-/</p>