DB2 Random Row Selection

Posted Wed Sep 14 08:32:00 EDT 2005

Pete posted earlier about selecting a single random row from various different types of database. I just wanted to follow up with the query to do this in IBM's DB2 (tested on 8.2)

SELECT * FROM <table> 
ORDER BY RAND() FETCH FIRST 1 ROWS ONLY

Related Books

Fundamentals of Database Systems (5th Edition) Beginning Database Design: From Novice to Professional Database Systems: Design, Implementation, and Management Database Design for Mere Mortals(R): A Hands-On Guide to Relational Database Design (2nd Edition) Databases Demystified (Demystified)

Comments

Post a Comment




Submit

About

My name is Tim Fanelli, I am a software engineer in Northern NY. I spend most of my time working, and when I can, I try to post interesting things here.

Cigar Dossiers