Notice that 12 is missing in the list. Even with x as (select distinct on(symb) * from stars) select * from x where nb = 12 order by nb;
nb = 12 is a duplicate with np = 34
Since your DISTINCT ON *subquery* doesn't specify an ordering which of those two are chosen as the representative record for M31 is non-determinstic.
If you want to ensure the lowest valued nb is chosen you need to sort the *subquery*. The first record the DISTINCT encounters is the one selected to represent.
Sorting in the outer/main query happens after the DISTINCT and so the record is already gone.