You definitely don't want to add newid()
to each row. That will undo the distinct
. Instead, use group by
with order by
newid()`:
SELECT top 4 b.BookID, b.Authors, b.ShortTitle
FROM Books b inner join
Publishers p
on b.PublisherID = p.PublisherID
GROUP BY b.BookId, b.Authors, B.ShortTitle
ORDER BY NEWID();
It will work fine. You can order by values that are not in the select
list.