Please observe following SQL query which gets 12 random rows.
SELECT TOP 12 ExportSystem.sysID, ExportSystem.sysNo, ExportSystem.sysName, Document.docArchiveNo FROM ExportSystem
INNER JOIN Customer ON ExportSystem.sysNo = Customer.expSysNr
INNER JOIN Department ON Customer.cusID = Department.cusID
INNER JOIN Level ON Level.levParentID = Department.levRootID
INNER JOIN Document ON Document.levID = Level.levID
GROUP BY ExportSystem.sysID, ExportSystem.sysNo, ExportSystem.sysName, Document.docArchiveNo
ORDER BY newid()
Results
SystemName ArchiveNo
RR 31676981
AA 28741154
AA 30435868
AA 29665408
AA 28116900
BB 31114199
RR 29080695
AA 29903701
VV 31890130
BB 29898481
BB 30892927
AA 30545346
I have tried many things but have not figured it out how to get same number of rows for each group. Currently there are two RR, six AA, three BB, and one VV. How to get 4 rows in each SystemName group.