I have a query that's doing quite a bit of heavy lifting on quite a large database. The way I have done it feels like it's jsut not optimal. I was wondering if anyone has any ideas that could point me in the right direction for optimising this query. Just to be clear I;m not looking for a re write jsut to get an idea of what approach to take here.
Just to clarify what I'm doing here. I want to get the sibling row of the selected rows details and merge it into one row.
SELECT rd.row_num,
rd.id,
rd.date,
rd.hashed,
rd.af,
rd.le,
rd.ti,
rd.co,
rd.row_num + 1 AS partner_row_number,
(SELECT date FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_date,
(SELECT id FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_id,
(SELECT af FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_af,
(SELECT len FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_le,
(SELECT ti FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_ti,
(SELECT co FROM rowedDESC
WHERE hashed = rd.hashed AND row_num = rd.row_num + 1) AS partner_co
FROM rowedDESC rd
WHERE rd.id IN (SELECT id FROM b)