title: Tricky SQL SELECT statement - combine two rows into two columns
body: <p><strong>My problem:</strong><br>
  I have a table with a <code>Channel &lt;int&gt;</code> and a <code>Value &lt;float&gt;</code> column, along with a timestamp and a couple of other columns with additional data. <code>Channel</code> is either <code>1</code> or <code>2</code>, and there is either 1 or 2 rows that have everything except channel and value the same.</p>
  
  <p>What I'd like to do is select this data into a new form, where the two channels show up as columns. I tried to do something with <code>GROUP BY</code>, but I couldn't figure out how to get the values into the correct columns based on the channel on the same row.</p>
  
  <p><strong>Example:</strong><br>
  For those of you that rather look at the data I have and the data I want and figure it out from there, here it is. What I have:</p>
  
  <pre><code> Channel    Value       Timestamp                OtherStuff
   1          0.2394      2010-07-09 13:00:00      'some other stuff'
   2          1.2348      2010-07-09 13:00:00      'some other stuff'
   1          24.2348     2010-07-09 12:58:00      'some other stuff'
   2          16.3728     2010-07-09 12:58:00      'some other stuff'
   1          12.284      2010-07-09 13:00:00      'unrelated things'
   2          9.6147      2010-07-09 13:00:00      'unrelated things'
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>Value1     Value2      Timestamp                OtherStuff
  0.2394     1.2348      2010-07-09 13:00:00      'some other stuff'
  24.2348    16.3728     2010-07-09 12:58:00      'some other stuff'
  12.284     9.6147      2010-07-09 13:00:00      'unrelated things'
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong> in response to some questions that have arised in comments, and a few follow up questions/clarifications:</p>
  
  <ul>
  <li><p>Yes, it is the combination of <code>Timestamp</code> and <code>OtherStuff</code> that links the two rows together. (<code>OtherStuff</code> is actually more than one column, but I simplified for brevity.) There are also a couple of other columns that are not necessarily equal, but should be kept just as they are.</p></li>
  <li><p>The table in question is already joined from two tables, where <code>Value</code>, <code>Channel</code> and <code>Timestamp</code> comes from one of them, and the rest (a total of 7 more columns, out of which 4 are always equal for "linked" rows, and the other three are mostly not). There have been a couple of suggestions using <code>INNER JOIN</code> - will these still work if I'm already joining stuff together (even though I don't have a <code>myTable</code> to join to itself)?</p></li>
  <li><p>There are <em>a lot</em> of rows with the same timestamp, so I need information from both the tables I'm joining to figure out which rows to link together.</p></li>
  <li><p>I have a lot of data. The input comes from measurement devices stationed all over the country, and most of them (if not all) upload measurements (for up to 4 channels) every 2 minutes. Right now we have about 1000 devices online, so this means an addidtion of on average approximately 1000 rows every minute. I need to consider values that are up to at least 3, preferrably 6, hours old, which means 180 000 to 360 000 rows in the table with channel, value and timestamp.</p></li>
  </ul>