I discovered a nasty bug in the way Sybase Iq last_value over partition works. More precisely it returns random values. On the other hand first_value is working fine so for now I am using that one instead, with reverse ordering in partitions. But it makes my queries a little harder to understand. Try this eg: Let's say we have table TestLastValueTable TableId RequestId Sender MessageNumber Location 1 1 alan 2 London 2 1 mary 3 Paris 3 1 mike 1 Sevilla 4 2 gaga 2 Paris 5 2 gugu 3 Sevilla When using ......