A query with a SKIP in a subquery produced the wrong result. For example, the following queries should all return the same number of rows:
select c.cust_id,c.name,(select top 1 cust_id from cust where ref_id=c.cust_id) as ref from cust c;
select c.cust_id,c.name,(select top 1 skip 1 cust_id from cust where ref_id=c.cust_id ORDER BY cust_id) as ref from cust c ORDER BY c.cust_id;
select c.cust_id,c.name,(select top 1 skip 2 cust_id from cust where ref_id=c.cust_id ORDER BY cust_id) as ref from cust c ORDER BY c.cust_id;
The logic has been modified to correct this.