title: Combining rows without a unique identifier
body: <p>I could use some help on developing a way to combine rows of data when the rows don't contain unique identifiers that the other rows reference. There is a pri_key, but the trailing rows never reference that key. </p>
  
  <p><strong>Disclaimer:</strong> I have no control over the design of the table. This is a query I'm running against a database of software we've purchased and have in production. </p>
  
  <p>Here's a sample similar to the data I'm looking at:</p>
  
  <pre><code>pri_key   |   personID   |   Type   |   reference   |   details   |   date_time
  101              1            A        Renewal #001   Trans # 001   2014-04-01 09:30:00
  102              1            B        Modify  #001   Expires 30d   2014-04-01 09:30:00
  104              1            A        Renewal #001   Trans # 002   2014-04-01 09:30:00
  105              1            B        Modify  #001   Expires 60d   2014-04-01 09:30:00
  108              2            A        Renewal #020   Trans # 003   2014-04-21 14:30:00
  109              2            B        Modify  #020   Expires 45d   2014-04-21 14:30:00
  111              3            A        Renewal #140   Trans # 004   2014-05-11 12:30:00
  112              3            B        Modify  #140   Expires 90d   2014-05-11 12:30:00
  </code></pre>
  
  <p>There are hundreds more rows, some personID's have 4 rows, others have 2. There's always a B type row following an A type row and that's what I'm after. From what I can surmise, the pri_key always increases by 1 for the B type row, but there are gaps between pri_keys as seen in the sample. A and B also always have the exact same time stamp.</p>
  
  <p>Using the sample above, here's what I'd like to see:</p>
  
  <pre><code>pri_key   |   personID   |   Type   |   reference   |   details   |   date_time         |   Modify    |   Expires
  101              1            A        Renewal #001   Trans # 001   2014-04-01 09:30:00  Modify  #001    Expires 30d
  104              1            A        Renewal #001   Trans # 002   2014-04-01 09:30:00  Modify  #001    Expires 60d
  108              2            A        Renewal #020   Trans # 003   2014-04-21 14:30:00  Modify  #020    Expires 45d
  111              3            A        Renewal #140   Trans # 004   2014-05-11 12:30:00  Modify  #140    Expires 90d
  </code></pre>
  
  <p>Essentially, I need the "expires" information from the B type's <code>details</code> to roll up into the A type's row. However, I'm getting caught on the peronID's that have 2 sets of rows. When I run various attempts at <code>JOIN</code> statements, I end up with a doubled up <code>Expires</code> column:</p>
  
  <pre><code>pri_key   |   personID   |   Type   |   reference   |   details   |   date_time         |   Modify    |   Expires
  101              1            A        Renewal #001   Trans # 001   2014-04-01 09:30:00  Modify  #001    Expires 60d
  104              1            A        Renewal #001   Trans # 002   2014-04-01 09:30:00  Modify  #001    Expires 60d
  108              2            A        Renewal #020   Trans # 003   2014-04-21 14:30:00  Modify  #020    Expires 45d
  111              3            A        Renewal #140   Trans # 004   2014-05-11 12:30:00  Modify  #140    Expires 90d
  </code></pre>
  
  <p>I'm currently thinking I need to find a way to use the <code>pri_key</code> +1 increments to my advantage, but I'm not sure that's the best approach or even how to properly handle that. Can anyone make any suggestions? I'm aware that what I've written here may make perfect sense to me and no one else, so please let me know if I can clarify. Thanks!</p>
  
  <p><a href="http://sqlfiddle.com/#!6/78286/1" rel="nofollow">I've created a SQL Fiddle</a> with the sample data inserted if it's easier for anyone to reference that. </p>