How do I pick distinct as well as random rows from a SQL Server 2008/2005 table?
I have a list of tips from which I need to pick a few tips randomly and they must be unique too.
I tried:
Select
Distinct Tips
From
jfpastrologytips
Where
GetDate() <= validtill
Order by
NewId()
and got commissioned with exception
Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
You can get around this by using
GROUP BYinstead ofDISTINCT