title: Using a single SQL correlated sub-query to get two columns
body: <p>My problem is represented by the following query:</p>
  
  <pre><code>SELECT 
    b.row_id, b.x, b.y, b.something,
    (SELECT a.x FROM my_table a WHERE a.row_id = (b.row_id - 1), a.something != 42 ) AS source_x,
    (SELECT a.y FROM my_table a WHERE a.row_id = (b.row_id - 1), a.something != 42 ) AS source_y
  FROM 
    my_table b
  </code></pre>
  
  <p>I'm using the same subquery statement twice, for getting both <code>source_x</code> and <code>source_y</code>.
  That's why I'm wondering if it's possible to do it using one subquery only?</p>
  
  <p>Because once I run this query on my real data (millions of rows) it seems to never finish and take hours, if not days (my connection hang up before the end). </p>
  
  <p>I am using PostgreSQL 8.4</p>