
MySQL
Get flash to fully experience Pearltrees
As a follow up to my earlier article about fetching a single random row from MySQL I will tell you today, how you can fetch multiple random rows from a table without any hassle. Compared to the solution with fetching a single random row, fetching multiple random rows requires some tricks. Let us start with creating two new test tables: CREATE TABLE `test` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR( 32 ) NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB; CREATE TABLE `test_gapless` ( `test_id` INT UNSIGNED NOT NULL, `random_id` INT UNSIGNED NOT NULL, PRIMARY KEY (`test_id`), UNIQUE (`random_id`) ) ENGINE = InnoDB;

