It looks to me that your main problem here is that the

number of COLUMNS of your result set is increasing indefinitely, if you really want to compare EACH new row

with ALL the previous ones.

I don’t know what database you are using, but for example

you use Oracle8i or higher, then you can easily use an

analytical function named LAG for comparing the current

row’s values with the values in ANY of the previous rows.

For example:

LAG(First,2) OVER (ORDER BY KoloId)

means “the value of First in the row that is 2 rows preceeding the current row in the ordering indicated.

Another solution could be to self-join the table to itself,

like this

SELECT …

FROM my_table t1,

my_table t2

where t2.KoloId > t1.KoloId

This allows you to compare EACH row to each of the preceeding rows, but, again, you should find a method to

decide upon how many columns you want to return,

which means, how many preceeding rows do you want to

compare with.

Rgds,

Iudith