Random in SQL - SQL For Programmers
Last week I had an interesting assignment: Given a specific record, randomly retrieve three related records from the database.
Naturally, as a programmer, I started looking for the SQL random function. Which I found.
But even as I was searching for how to use that function, I was thinking to myself, “How am I going to structure things in such a way so as to randomly select the records once I have the function? It isn’t like I can retrieve the records into an array and then select them out. Am I going to have to retrieve them into a temp table?”
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

One of the things it took me a while to figure out was how to get a stored procedure to loop through data in a table and pull out specific data I needed.
You may think that you don’t need a temporary table. But if you’ve ever retrieved data from your database or retrieved data from a table and put it in a list of some sort simply to process it further with your code, you need to learn about temporary tables.