SQL - Select everything after a certain row
Perhaps something like this:
SELECT
  ...,
  (
    SELECT value 
    FROM
      (SELECT MAX(mtsub.ID) maxid FROM mytable mtsub WHERE mtsub.type_ = 'STATUS' AND mtsub.id &lt; my.ID) maxids 
      INNER JOIN my_table mtsub2 ON mtsub2.id = maxes.maxid
  ) recent_status_value
FROM
  my_table mt ...

This should result in a column that has the most recently encountered status row's value - you can then where it for being equal to 40 in an outer query
Not a huge fan of &quot;selects in the select list&quot; coordination but if you don't have window functions available to help spread the most recent value of status over some rows..
Where'ing the mtsub queries to restrict their rows may help performance too; I left it out for clarity of code