in reply to Problem with database under Win32

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:
select table2.* 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.

Replies are listed 'Best First'.
Re: Re: Problem with database under Win32
by NetWallah (Canon) on Nov 23, 2003 at 16:47 UTC
    Using SELECT TOP 1 From ..... ORDER BY ID DESC may be faster than trying a "Max".

    I am not a SQL weenie though - you may want to check with your DBA as to why the subquery seems "slower".

      I am not sure - if you MAX() an index, you usually get top performance with no disk access at all; in any other case you need a table scan to know all the values, so you can max() them. My actual query is not any way similar to the one I am presenting here (it's a five-page belemoth, just in the case you wonder, even with all repeated subqueries extracted!)