My problem is represented by the following query:
SELECT b.row_id, bx, by, b.something, (SELECT ax FROM my_table a WHERE a.row_id = (b.row_id - 1), a.something != 42 ) AS source_x, (SELECT ay FROM my_table a WHERE a.row_id = (b.row_id - 1), a.something != 42 ) AS source_y FROM my_table b
I use the same subquery operator twice to get both source_x and source_y . This is why I am wondering if it is possible to do this using only one subquery?
Because, as soon as I run this query on my real data (millions of rows), it seems to never end and takes hours, if not days (my connection hangs to the end).
I am using PostgreSQL 8.4
source share