Needing to select a random row in MS SQL is definitely not your everyday task but then again, I'm not your everyday developer am I? . Luckily finding this SQL query was a piece of cake. Check the code below:
SELECT TOP 1 <column> FROM <table> ORDER BY NEWID()
Interesting thing is, I've never heard of NEWID() before and MSDN's description for it doesn't fit in with its use above at all! Anyway, it works.. so hurray!
Special thanks to this site for providing the code and I also recommend it as it has examples for selecting a random row in MySQL and PostgreSQL.
tagged: professional // Comments [0]
Related posts:Regular expressionsVS2005, ASP.NET 2 & DLLs, DLLs..MS's ASP.NET and.. PHP2-way databinding cascading drop down lists within a FormViewApplicationName Property when customising providersFormatting strings/numbers in .NET
Disclaimer The posts on this blog are provided "AS IS" with no warranties. The opinions expressed herein are my own personal opinions and do not represent any other person's views in anyway.