Thursday, October 8, 2009

how to shuffle records when querying from database

If we want to have records shuffled in a random manner then
you need to add the "ORDER BY NEWID()" as follows.

SELECT p.*,c.*
FROM dbo.tblPartnerInfo AS p
LEFT JOIN dbo.tblCountry AS c
ON p.CountryID=c.CountryID
WHERE p.CountryID=@CountryID
ORDER BY NEWID()

No comments: