(a “How it works” – question)
Suppose I have this table :
Id val
------------------
1 a <--
1 a
1 a
2 b <--
2 b
2 b
Now lets say I want the marked rows :
Can I count on this query :
select id,val from (
select id , val , row_number() over (partition by id order by id) as rn
) k where rn=1
to give me the Selected rows ?
(notice the order by clause). will it consider the order as the order they were inserted ?
The behaviour is not guaranteed. Your query will return two rows, but which ones is undefined.
When I experiment with
the results are variable, depending on the order of insertion, but not consistently the first inserted rows.