Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Comment supprimer les doublons dans la pagination

Vous pouvez appliquer distinct avant row_number en utilisant une sous-requête :

select  *
from    (
        select  row_number() over (order by tbl.id desc) as row
        ,       *
        from    (
                select  distinct t1.ID
                ,       tb1.name
                from    dbo.tb1 as t1
                join    dbo.tb2 as t2
                on      t1.ID = t2.id_tb1
                ) as sub_dist
        ) as sub_with_rn
where   row between 1 and 7