clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3798834 fiddles created (41834 in the last week).

create table cursortable( id varchar(10), date date, time time);
 hidden batch(es)


insert into cursortable values('68' , '2017-10-28' , '22:00:00'); insert into cursortable values('d3' , '2017-11-03' , null); insert into cursortable values('dd' , '2017-11-03' , '21:45:00'); insert into cursortable values('62' , '2017-11-04' , '14:00:00'); insert into cursortable values('a1' , '2017-11-04' , '19:40:00');
 hidden batch(es)


select *,row_number()over(order by date,time,id)rn from cursortable
id date time rn
68 2017-10-28 22:00:00 1
d3 2017-11-03 2
dd 2017-11-03 21:45:00 3
62 2017-11-04 14:00:00 4
a1 2017-11-04 19:40:00 5
 hidden batch(es)


with cte as ( select *,row_number()over(order by date,time,id)rn from cursortable ) select * from cte where rn<3
id date time rn
68 2017-10-28 22:00:00 1
d3 2017-11-03 2
 hidden batch(es)