I have the following data set on Postgresql:
create table data (
id int,
stage varchar(255),
name varchar(255)
);
id stage name
----------------------------
1 pyramid act 1
2 pyramid act 2
3 NULL act 3
4 NULL act 4
5 NULL act 5
6 NULL act 6
7 NULL act 7
8 NULL act 8
9 NULL act 9
10 NULL act 10
11 NULL act 11
12 NULL act 12
13 shangri la act 13
I query all the data table and sort by stage with nulls last/ limit:
select *
from data
order by stage asc nulls first
limit 5;
Result:
id stage name
----------------------------
6 NULL act 6
3 NULL act 3
4 NULL act 4
5 NULL act 5
7 NULL act 7
----------------------------
The issue when I change the limit value I get a different sorting result:
select *
from data
order by stage asc nulls first
limit 3;
Result:
id stage name
----------------------------
4 NULL act 4
3 NULL act 3
5 NULL act 5
----------------------------
PS: I'm using Postgresql PostgreSQL 10.3.