Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Wie entferne ich Duplikate beim Paging

Sie könnten distinct anwenden vor row_number mit einer Unterabfrage:

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