Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come rimuovo i duplicati nel paging

Potresti applicare distinct prima di row_number utilizzando una sottoquery:

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