What is the best way of transcribing the following Transact-SQL code to Informix Dynamic Server (IDS) 9.40:
Objective: I need the first 50 orders with their respective order lines
select *
from (select top 50 * from orders) a inner join lines b
on a.idOrder = b.idOrder
My problem is with the subselect because Informix does not allow the FIRST option in the subselect.
Any simple idea?.
The official answer would be ‘Please upgrade from IDS 9.40 since it is no longer supported by IBM’. That is, IDS 9.40 is not a current version – and should (ideally) not be used.
Solution for IDS 11.50
Using IDS 11.50, I can write:
This is more or less equivalent to your query. Consequently, if you use a current version of IDS, you can write the query using almost the same notation as in Transact-SQL (using FIRST in place of TOP).
Solution for IDS 9.40
What can you do in IDS 9.40? Excuse me a moment…I have to run up my IDS 9.40.xC7 server (this fix pack was released in 2005; the original release was probably in late 2003)…
First problem – IDS 9.40 does not allow sub-queries in the FROM clause.
Second problem – IDS 9.40 does not allow ‘FIRST n’ notation in either of these contexts:
Third problem – IDS 9.40 doesn’t have a simple ROWNUM.
So, to work around these, we can write (using a temporary table – we’ll remove that later):
This produces the same answer as the single query in IDS 11.50. Can we avoid the temporary table? Yes, but it is more verbose:
Applying that to the original orders plus order lines example is left as an exercise for the reader.
Relevant subset of schema for ‘Table of Elements’:
Output (on my sample database):