Web Development Tips and Tricks

In this blog, I will be posting tips and tricks which will be useful for web development.

Friday, February 18, 2005

To select a random record from database from the latest 5 entries.

I have a a table named cms_imagelib and I would like to select a random record from the lasted added 5 records.. I used the following query to retrieve the required record..

Select newID(),a.imageID,a.ImageName as ImageName from cms_ImageLib as a where ImageID in
(Select top 5 ImageID from cms_imagelib where active='1' and moderated='1' order by creation_time) order by newID();

0 Comments:

Post a Comment

<< Home