Given the requirement:
I'd like to do a single query that will get me all txn_ids for all transactions where the transaction is not the most recent (highest txn_id) for the account_id.
it seems that answers which give you transaction IDs for a single account at a time are missing the point of the query.
To get the list of transaction IDs that must be retained (or ignored) we can write:
SELECT MAX(txn_id) AS max_txn_id, account_id
FROM UnnamedTable
GROUP BY account_id;
Now we need to get the list of transaction IDs not found in that list. That isn't wholly straight-forward:
SELECT txn_id, account_id
FROM UnnamedTable
WHERE txn_id NOT IN
(SELECT max_txn_id
FROM (SELECT MAX(txn_id) AS max_txn_id, account_id
FROM UnnamedTable
GROUP BY account_id
)
)
Anyway, that works OK with IBM Informix Dynamic Server 11.50 and the table and data below:
create table unnamedtable(txn_id integer not null, account_id integer not null);
insert into unnamedtable values(1, 12);
insert into unnamedtable values(2, 12);
insert into unnamedtable values(3, 12);
insert into unnamedtable values(4, 13);
yielding the results:
1 12
2 12