count duplicate records and select first 2
select * from (SELECT
    row_number() over (partition by 1,2,3,4 order by 1,2) as RowNo,
    a.dbsnum,
    b.chknum,
    a.name,
    b.fname
    FROM
    sysdbspaces a, syschunks b where a.dbsnum = b.dbsnum
    GROUP BY
    1,2,3,4) as innerSelect
where RowNo &lt;=2