Depending on the uniqueness of the id field in table1, and how close your real problem is to this example, but maybe this would work:
from table1, table2
where table1.id = table2.id
order by id desc
And fetch until id changes. And I don't know if DBI would help either, but if you have to rewrite the bits that don't work anyway, and if DBI does work, I'd consider that as an option. DBD::Sybase
supports multiple result sets (and it supports SQL Server to some extent), I don't know if that is what you are referring to, or if that's applicable here.