This tutorial shows how to select items randomly from each category in MySQL. So here we will select exactly one item randomly from each category. People who need sometimes to select photo from each photo category and display them on the page for animation purpose will be benefited.
In this example I have used table name starts with item. You can change the name and column names as per your needs and you will get the same results.

Final Output:

random item selection for each category in mysql

First create item category table which holds the category for items


Create table items which holds items from each category above


Insert dummy values to item_categories table


Insert dummy values to items table


Execute the below query


That’s all. Thanks for your reading. Please do not hesitate to ask any question by leaving a comment.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.